tomoto 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (420) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +123 -0
  5. data/ext/tomoto/ext.cpp +245 -0
  6. data/ext/tomoto/extconf.rb +28 -0
  7. data/lib/tomoto.rb +12 -0
  8. data/lib/tomoto/ct.rb +11 -0
  9. data/lib/tomoto/hdp.rb +11 -0
  10. data/lib/tomoto/lda.rb +67 -0
  11. data/lib/tomoto/version.rb +3 -0
  12. data/vendor/EigenRand/EigenRand/Core.h +1139 -0
  13. data/vendor/EigenRand/EigenRand/Dists/Basic.h +111 -0
  14. data/vendor/EigenRand/EigenRand/Dists/Discrete.h +877 -0
  15. data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +108 -0
  16. data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +626 -0
  17. data/vendor/EigenRand/EigenRand/EigenRand +19 -0
  18. data/vendor/EigenRand/EigenRand/Macro.h +24 -0
  19. data/vendor/EigenRand/EigenRand/MorePacketMath.h +978 -0
  20. data/vendor/EigenRand/EigenRand/PacketFilter.h +286 -0
  21. data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +624 -0
  22. data/vendor/EigenRand/EigenRand/RandUtils.h +413 -0
  23. data/vendor/EigenRand/EigenRand/doc.h +220 -0
  24. data/vendor/EigenRand/LICENSE +21 -0
  25. data/vendor/EigenRand/README.md +288 -0
  26. data/vendor/eigen/COPYING.BSD +26 -0
  27. data/vendor/eigen/COPYING.GPL +674 -0
  28. data/vendor/eigen/COPYING.LGPL +502 -0
  29. data/vendor/eigen/COPYING.MINPACK +52 -0
  30. data/vendor/eigen/COPYING.MPL2 +373 -0
  31. data/vendor/eigen/COPYING.README +18 -0
  32. data/vendor/eigen/Eigen/CMakeLists.txt +19 -0
  33. data/vendor/eigen/Eigen/Cholesky +46 -0
  34. data/vendor/eigen/Eigen/CholmodSupport +48 -0
  35. data/vendor/eigen/Eigen/Core +537 -0
  36. data/vendor/eigen/Eigen/Dense +7 -0
  37. data/vendor/eigen/Eigen/Eigen +2 -0
  38. data/vendor/eigen/Eigen/Eigenvalues +61 -0
  39. data/vendor/eigen/Eigen/Geometry +62 -0
  40. data/vendor/eigen/Eigen/Householder +30 -0
  41. data/vendor/eigen/Eigen/IterativeLinearSolvers +48 -0
  42. data/vendor/eigen/Eigen/Jacobi +33 -0
  43. data/vendor/eigen/Eigen/LU +50 -0
  44. data/vendor/eigen/Eigen/MetisSupport +35 -0
  45. data/vendor/eigen/Eigen/OrderingMethods +73 -0
  46. data/vendor/eigen/Eigen/PaStiXSupport +48 -0
  47. data/vendor/eigen/Eigen/PardisoSupport +35 -0
  48. data/vendor/eigen/Eigen/QR +51 -0
  49. data/vendor/eigen/Eigen/QtAlignedMalloc +40 -0
  50. data/vendor/eigen/Eigen/SPQRSupport +34 -0
  51. data/vendor/eigen/Eigen/SVD +51 -0
  52. data/vendor/eigen/Eigen/Sparse +36 -0
  53. data/vendor/eigen/Eigen/SparseCholesky +45 -0
  54. data/vendor/eigen/Eigen/SparseCore +69 -0
  55. data/vendor/eigen/Eigen/SparseLU +46 -0
  56. data/vendor/eigen/Eigen/SparseQR +37 -0
  57. data/vendor/eigen/Eigen/StdDeque +27 -0
  58. data/vendor/eigen/Eigen/StdList +26 -0
  59. data/vendor/eigen/Eigen/StdVector +27 -0
  60. data/vendor/eigen/Eigen/SuperLUSupport +64 -0
  61. data/vendor/eigen/Eigen/UmfPackSupport +40 -0
  62. data/vendor/eigen/Eigen/src/Cholesky/LDLT.h +673 -0
  63. data/vendor/eigen/Eigen/src/Cholesky/LLT.h +542 -0
  64. data/vendor/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h +99 -0
  65. data/vendor/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +639 -0
  66. data/vendor/eigen/Eigen/src/Core/Array.h +329 -0
  67. data/vendor/eigen/Eigen/src/Core/ArrayBase.h +226 -0
  68. data/vendor/eigen/Eigen/src/Core/ArrayWrapper.h +209 -0
  69. data/vendor/eigen/Eigen/src/Core/Assign.h +90 -0
  70. data/vendor/eigen/Eigen/src/Core/AssignEvaluator.h +935 -0
  71. data/vendor/eigen/Eigen/src/Core/Assign_MKL.h +178 -0
  72. data/vendor/eigen/Eigen/src/Core/BandMatrix.h +353 -0
  73. data/vendor/eigen/Eigen/src/Core/Block.h +452 -0
  74. data/vendor/eigen/Eigen/src/Core/BooleanRedux.h +164 -0
  75. data/vendor/eigen/Eigen/src/Core/CommaInitializer.h +160 -0
  76. data/vendor/eigen/Eigen/src/Core/ConditionEstimator.h +175 -0
  77. data/vendor/eigen/Eigen/src/Core/CoreEvaluators.h +1688 -0
  78. data/vendor/eigen/Eigen/src/Core/CoreIterators.h +127 -0
  79. data/vendor/eigen/Eigen/src/Core/CwiseBinaryOp.h +184 -0
  80. data/vendor/eigen/Eigen/src/Core/CwiseNullaryOp.h +866 -0
  81. data/vendor/eigen/Eigen/src/Core/CwiseTernaryOp.h +197 -0
  82. data/vendor/eigen/Eigen/src/Core/CwiseUnaryOp.h +103 -0
  83. data/vendor/eigen/Eigen/src/Core/CwiseUnaryView.h +128 -0
  84. data/vendor/eigen/Eigen/src/Core/DenseBase.h +611 -0
  85. data/vendor/eigen/Eigen/src/Core/DenseCoeffsBase.h +681 -0
  86. data/vendor/eigen/Eigen/src/Core/DenseStorage.h +570 -0
  87. data/vendor/eigen/Eigen/src/Core/Diagonal.h +260 -0
  88. data/vendor/eigen/Eigen/src/Core/DiagonalMatrix.h +343 -0
  89. data/vendor/eigen/Eigen/src/Core/DiagonalProduct.h +28 -0
  90. data/vendor/eigen/Eigen/src/Core/Dot.h +318 -0
  91. data/vendor/eigen/Eigen/src/Core/EigenBase.h +159 -0
  92. data/vendor/eigen/Eigen/src/Core/ForceAlignedAccess.h +146 -0
  93. data/vendor/eigen/Eigen/src/Core/Fuzzy.h +155 -0
  94. data/vendor/eigen/Eigen/src/Core/GeneralProduct.h +455 -0
  95. data/vendor/eigen/Eigen/src/Core/GenericPacketMath.h +593 -0
  96. data/vendor/eigen/Eigen/src/Core/GlobalFunctions.h +187 -0
  97. data/vendor/eigen/Eigen/src/Core/IO.h +225 -0
  98. data/vendor/eigen/Eigen/src/Core/Inverse.h +118 -0
  99. data/vendor/eigen/Eigen/src/Core/Map.h +171 -0
  100. data/vendor/eigen/Eigen/src/Core/MapBase.h +303 -0
  101. data/vendor/eigen/Eigen/src/Core/MathFunctions.h +1415 -0
  102. data/vendor/eigen/Eigen/src/Core/MathFunctionsImpl.h +101 -0
  103. data/vendor/eigen/Eigen/src/Core/Matrix.h +459 -0
  104. data/vendor/eigen/Eigen/src/Core/MatrixBase.h +529 -0
  105. data/vendor/eigen/Eigen/src/Core/NestByValue.h +110 -0
  106. data/vendor/eigen/Eigen/src/Core/NoAlias.h +108 -0
  107. data/vendor/eigen/Eigen/src/Core/NumTraits.h +248 -0
  108. data/vendor/eigen/Eigen/src/Core/PermutationMatrix.h +633 -0
  109. data/vendor/eigen/Eigen/src/Core/PlainObjectBase.h +1035 -0
  110. data/vendor/eigen/Eigen/src/Core/Product.h +186 -0
  111. data/vendor/eigen/Eigen/src/Core/ProductEvaluators.h +1112 -0
  112. data/vendor/eigen/Eigen/src/Core/Random.h +182 -0
  113. data/vendor/eigen/Eigen/src/Core/Redux.h +505 -0
  114. data/vendor/eigen/Eigen/src/Core/Ref.h +283 -0
  115. data/vendor/eigen/Eigen/src/Core/Replicate.h +142 -0
  116. data/vendor/eigen/Eigen/src/Core/ReturnByValue.h +117 -0
  117. data/vendor/eigen/Eigen/src/Core/Reverse.h +211 -0
  118. data/vendor/eigen/Eigen/src/Core/Select.h +162 -0
  119. data/vendor/eigen/Eigen/src/Core/SelfAdjointView.h +352 -0
  120. data/vendor/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +47 -0
  121. data/vendor/eigen/Eigen/src/Core/Solve.h +188 -0
  122. data/vendor/eigen/Eigen/src/Core/SolveTriangular.h +235 -0
  123. data/vendor/eigen/Eigen/src/Core/SolverBase.h +130 -0
  124. data/vendor/eigen/Eigen/src/Core/StableNorm.h +221 -0
  125. data/vendor/eigen/Eigen/src/Core/Stride.h +111 -0
  126. data/vendor/eigen/Eigen/src/Core/Swap.h +67 -0
  127. data/vendor/eigen/Eigen/src/Core/Transpose.h +403 -0
  128. data/vendor/eigen/Eigen/src/Core/Transpositions.h +407 -0
  129. data/vendor/eigen/Eigen/src/Core/TriangularMatrix.h +983 -0
  130. data/vendor/eigen/Eigen/src/Core/VectorBlock.h +96 -0
  131. data/vendor/eigen/Eigen/src/Core/VectorwiseOp.h +695 -0
  132. data/vendor/eigen/Eigen/src/Core/Visitor.h +273 -0
  133. data/vendor/eigen/Eigen/src/Core/arch/AVX/Complex.h +451 -0
  134. data/vendor/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +439 -0
  135. data/vendor/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +637 -0
  136. data/vendor/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +51 -0
  137. data/vendor/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +391 -0
  138. data/vendor/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +1316 -0
  139. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +430 -0
  140. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +322 -0
  141. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +1061 -0
  142. data/vendor/eigen/Eigen/src/Core/arch/CUDA/Complex.h +103 -0
  143. data/vendor/eigen/Eigen/src/Core/arch/CUDA/Half.h +674 -0
  144. data/vendor/eigen/Eigen/src/Core/arch/CUDA/MathFunctions.h +91 -0
  145. data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMath.h +333 -0
  146. data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMathHalf.h +1124 -0
  147. data/vendor/eigen/Eigen/src/Core/arch/CUDA/TypeCasting.h +212 -0
  148. data/vendor/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +29 -0
  149. data/vendor/eigen/Eigen/src/Core/arch/Default/Settings.h +49 -0
  150. data/vendor/eigen/Eigen/src/Core/arch/NEON/Complex.h +490 -0
  151. data/vendor/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +91 -0
  152. data/vendor/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +760 -0
  153. data/vendor/eigen/Eigen/src/Core/arch/SSE/Complex.h +471 -0
  154. data/vendor/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +562 -0
  155. data/vendor/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +895 -0
  156. data/vendor/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +77 -0
  157. data/vendor/eigen/Eigen/src/Core/arch/ZVector/Complex.h +397 -0
  158. data/vendor/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +137 -0
  159. data/vendor/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +945 -0
  160. data/vendor/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +168 -0
  161. data/vendor/eigen/Eigen/src/Core/functors/BinaryFunctors.h +475 -0
  162. data/vendor/eigen/Eigen/src/Core/functors/NullaryFunctors.h +188 -0
  163. data/vendor/eigen/Eigen/src/Core/functors/StlFunctors.h +136 -0
  164. data/vendor/eigen/Eigen/src/Core/functors/TernaryFunctors.h +25 -0
  165. data/vendor/eigen/Eigen/src/Core/functors/UnaryFunctors.h +792 -0
  166. data/vendor/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +2156 -0
  167. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +492 -0
  168. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +311 -0
  169. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +145 -0
  170. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +122 -0
  171. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +619 -0
  172. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +136 -0
  173. data/vendor/eigen/Eigen/src/Core/products/Parallelizer.h +163 -0
  174. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +521 -0
  175. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +287 -0
  176. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +260 -0
  177. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +118 -0
  178. data/vendor/eigen/Eigen/src/Core/products/SelfadjointProduct.h +133 -0
  179. data/vendor/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +93 -0
  180. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +466 -0
  181. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +315 -0
  182. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +350 -0
  183. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +255 -0
  184. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +335 -0
  185. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +163 -0
  186. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverVector.h +145 -0
  187. data/vendor/eigen/Eigen/src/Core/util/BlasUtil.h +398 -0
  188. data/vendor/eigen/Eigen/src/Core/util/Constants.h +547 -0
  189. data/vendor/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +83 -0
  190. data/vendor/eigen/Eigen/src/Core/util/ForwardDeclarations.h +302 -0
  191. data/vendor/eigen/Eigen/src/Core/util/MKL_support.h +130 -0
  192. data/vendor/eigen/Eigen/src/Core/util/Macros.h +1001 -0
  193. data/vendor/eigen/Eigen/src/Core/util/Memory.h +993 -0
  194. data/vendor/eigen/Eigen/src/Core/util/Meta.h +534 -0
  195. data/vendor/eigen/Eigen/src/Core/util/NonMPL2.h +3 -0
  196. data/vendor/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +27 -0
  197. data/vendor/eigen/Eigen/src/Core/util/StaticAssert.h +218 -0
  198. data/vendor/eigen/Eigen/src/Core/util/XprHelper.h +821 -0
  199. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h +346 -0
  200. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur.h +459 -0
  201. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +91 -0
  202. data/vendor/eigen/Eigen/src/Eigenvalues/EigenSolver.h +622 -0
  203. data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +418 -0
  204. data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +226 -0
  205. data/vendor/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h +374 -0
  206. data/vendor/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +158 -0
  207. data/vendor/eigen/Eigen/src/Eigenvalues/RealQZ.h +654 -0
  208. data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur.h +546 -0
  209. data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +77 -0
  210. data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +870 -0
  211. data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +87 -0
  212. data/vendor/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h +556 -0
  213. data/vendor/eigen/Eigen/src/Geometry/AlignedBox.h +392 -0
  214. data/vendor/eigen/Eigen/src/Geometry/AngleAxis.h +247 -0
  215. data/vendor/eigen/Eigen/src/Geometry/EulerAngles.h +114 -0
  216. data/vendor/eigen/Eigen/src/Geometry/Homogeneous.h +497 -0
  217. data/vendor/eigen/Eigen/src/Geometry/Hyperplane.h +282 -0
  218. data/vendor/eigen/Eigen/src/Geometry/OrthoMethods.h +234 -0
  219. data/vendor/eigen/Eigen/src/Geometry/ParametrizedLine.h +195 -0
  220. data/vendor/eigen/Eigen/src/Geometry/Quaternion.h +814 -0
  221. data/vendor/eigen/Eigen/src/Geometry/Rotation2D.h +199 -0
  222. data/vendor/eigen/Eigen/src/Geometry/RotationBase.h +206 -0
  223. data/vendor/eigen/Eigen/src/Geometry/Scaling.h +170 -0
  224. data/vendor/eigen/Eigen/src/Geometry/Transform.h +1542 -0
  225. data/vendor/eigen/Eigen/src/Geometry/Translation.h +208 -0
  226. data/vendor/eigen/Eigen/src/Geometry/Umeyama.h +166 -0
  227. data/vendor/eigen/Eigen/src/Geometry/arch/Geometry_SSE.h +161 -0
  228. data/vendor/eigen/Eigen/src/Householder/BlockHouseholder.h +103 -0
  229. data/vendor/eigen/Eigen/src/Householder/Householder.h +172 -0
  230. data/vendor/eigen/Eigen/src/Householder/HouseholderSequence.h +470 -0
  231. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +226 -0
  232. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +228 -0
  233. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +246 -0
  234. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +400 -0
  235. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +462 -0
  236. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +394 -0
  237. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +216 -0
  238. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +115 -0
  239. data/vendor/eigen/Eigen/src/Jacobi/Jacobi.h +462 -0
  240. data/vendor/eigen/Eigen/src/LU/Determinant.h +101 -0
  241. data/vendor/eigen/Eigen/src/LU/FullPivLU.h +891 -0
  242. data/vendor/eigen/Eigen/src/LU/InverseImpl.h +415 -0
  243. data/vendor/eigen/Eigen/src/LU/PartialPivLU.h +611 -0
  244. data/vendor/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h +83 -0
  245. data/vendor/eigen/Eigen/src/LU/arch/Inverse_SSE.h +338 -0
  246. data/vendor/eigen/Eigen/src/MetisSupport/MetisSupport.h +137 -0
  247. data/vendor/eigen/Eigen/src/OrderingMethods/Amd.h +445 -0
  248. data/vendor/eigen/Eigen/src/OrderingMethods/Eigen_Colamd.h +1843 -0
  249. data/vendor/eigen/Eigen/src/OrderingMethods/Ordering.h +157 -0
  250. data/vendor/eigen/Eigen/src/PaStiXSupport/PaStiXSupport.h +678 -0
  251. data/vendor/eigen/Eigen/src/PardisoSupport/PardisoSupport.h +543 -0
  252. data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR.h +653 -0
  253. data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +97 -0
  254. data/vendor/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h +562 -0
  255. data/vendor/eigen/Eigen/src/QR/FullPivHouseholderQR.h +676 -0
  256. data/vendor/eigen/Eigen/src/QR/HouseholderQR.h +409 -0
  257. data/vendor/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h +68 -0
  258. data/vendor/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +313 -0
  259. data/vendor/eigen/Eigen/src/SVD/BDCSVD.h +1246 -0
  260. data/vendor/eigen/Eigen/src/SVD/JacobiSVD.h +804 -0
  261. data/vendor/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h +91 -0
  262. data/vendor/eigen/Eigen/src/SVD/SVDBase.h +315 -0
  263. data/vendor/eigen/Eigen/src/SVD/UpperBidiagonalization.h +414 -0
  264. data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky.h +689 -0
  265. data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +199 -0
  266. data/vendor/eigen/Eigen/src/SparseCore/AmbiVector.h +377 -0
  267. data/vendor/eigen/Eigen/src/SparseCore/CompressedStorage.h +258 -0
  268. data/vendor/eigen/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +352 -0
  269. data/vendor/eigen/Eigen/src/SparseCore/MappedSparseMatrix.h +67 -0
  270. data/vendor/eigen/Eigen/src/SparseCore/SparseAssign.h +216 -0
  271. data/vendor/eigen/Eigen/src/SparseCore/SparseBlock.h +603 -0
  272. data/vendor/eigen/Eigen/src/SparseCore/SparseColEtree.h +206 -0
  273. data/vendor/eigen/Eigen/src/SparseCore/SparseCompressedBase.h +341 -0
  274. data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +726 -0
  275. data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +148 -0
  276. data/vendor/eigen/Eigen/src/SparseCore/SparseDenseProduct.h +320 -0
  277. data/vendor/eigen/Eigen/src/SparseCore/SparseDiagonalProduct.h +138 -0
  278. data/vendor/eigen/Eigen/src/SparseCore/SparseDot.h +98 -0
  279. data/vendor/eigen/Eigen/src/SparseCore/SparseFuzzy.h +29 -0
  280. data/vendor/eigen/Eigen/src/SparseCore/SparseMap.h +305 -0
  281. data/vendor/eigen/Eigen/src/SparseCore/SparseMatrix.h +1403 -0
  282. data/vendor/eigen/Eigen/src/SparseCore/SparseMatrixBase.h +405 -0
  283. data/vendor/eigen/Eigen/src/SparseCore/SparsePermutation.h +178 -0
  284. data/vendor/eigen/Eigen/src/SparseCore/SparseProduct.h +169 -0
  285. data/vendor/eigen/Eigen/src/SparseCore/SparseRedux.h +49 -0
  286. data/vendor/eigen/Eigen/src/SparseCore/SparseRef.h +397 -0
  287. data/vendor/eigen/Eigen/src/SparseCore/SparseSelfAdjointView.h +656 -0
  288. data/vendor/eigen/Eigen/src/SparseCore/SparseSolverBase.h +124 -0
  289. data/vendor/eigen/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +198 -0
  290. data/vendor/eigen/Eigen/src/SparseCore/SparseTranspose.h +92 -0
  291. data/vendor/eigen/Eigen/src/SparseCore/SparseTriangularView.h +189 -0
  292. data/vendor/eigen/Eigen/src/SparseCore/SparseUtil.h +178 -0
  293. data/vendor/eigen/Eigen/src/SparseCore/SparseVector.h +478 -0
  294. data/vendor/eigen/Eigen/src/SparseCore/SparseView.h +253 -0
  295. data/vendor/eigen/Eigen/src/SparseCore/TriangularSolver.h +315 -0
  296. data/vendor/eigen/Eigen/src/SparseLU/SparseLU.h +773 -0
  297. data/vendor/eigen/Eigen/src/SparseLU/SparseLUImpl.h +66 -0
  298. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Memory.h +226 -0
  299. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Structs.h +110 -0
  300. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +301 -0
  301. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Utils.h +80 -0
  302. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_bmod.h +181 -0
  303. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_dfs.h +179 -0
  304. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +107 -0
  305. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +280 -0
  306. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +126 -0
  307. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +130 -0
  308. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_bmod.h +223 -0
  309. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_dfs.h +258 -0
  310. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pivotL.h +137 -0
  311. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h +136 -0
  312. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_relax_snode.h +83 -0
  313. data/vendor/eigen/Eigen/src/SparseQR/SparseQR.h +745 -0
  314. data/vendor/eigen/Eigen/src/StlSupport/StdDeque.h +126 -0
  315. data/vendor/eigen/Eigen/src/StlSupport/StdList.h +106 -0
  316. data/vendor/eigen/Eigen/src/StlSupport/StdVector.h +131 -0
  317. data/vendor/eigen/Eigen/src/StlSupport/details.h +84 -0
  318. data/vendor/eigen/Eigen/src/SuperLUSupport/SuperLUSupport.h +1027 -0
  319. data/vendor/eigen/Eigen/src/UmfPackSupport/UmfPackSupport.h +506 -0
  320. data/vendor/eigen/Eigen/src/misc/Image.h +82 -0
  321. data/vendor/eigen/Eigen/src/misc/Kernel.h +79 -0
  322. data/vendor/eigen/Eigen/src/misc/RealSvd2x2.h +55 -0
  323. data/vendor/eigen/Eigen/src/misc/blas.h +440 -0
  324. data/vendor/eigen/Eigen/src/misc/lapack.h +152 -0
  325. data/vendor/eigen/Eigen/src/misc/lapacke.h +16291 -0
  326. data/vendor/eigen/Eigen/src/misc/lapacke_mangling.h +17 -0
  327. data/vendor/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +332 -0
  328. data/vendor/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +552 -0
  329. data/vendor/eigen/Eigen/src/plugins/BlockMethods.h +1058 -0
  330. data/vendor/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +115 -0
  331. data/vendor/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +163 -0
  332. data/vendor/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +152 -0
  333. data/vendor/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +85 -0
  334. data/vendor/eigen/README.md +3 -0
  335. data/vendor/eigen/bench/README.txt +55 -0
  336. data/vendor/eigen/bench/btl/COPYING +340 -0
  337. data/vendor/eigen/bench/btl/README +154 -0
  338. data/vendor/eigen/bench/tensors/README +21 -0
  339. data/vendor/eigen/blas/README.txt +6 -0
  340. data/vendor/eigen/demos/mandelbrot/README +10 -0
  341. data/vendor/eigen/demos/mix_eigen_and_c/README +9 -0
  342. data/vendor/eigen/demos/opengl/README +13 -0
  343. data/vendor/eigen/unsupported/Eigen/CXX11/src/Tensor/README.md +1760 -0
  344. data/vendor/eigen/unsupported/README.txt +50 -0
  345. data/vendor/tomotopy/LICENSE +21 -0
  346. data/vendor/tomotopy/README.kr.rst +375 -0
  347. data/vendor/tomotopy/README.rst +382 -0
  348. data/vendor/tomotopy/src/Labeling/FoRelevance.cpp +362 -0
  349. data/vendor/tomotopy/src/Labeling/FoRelevance.h +88 -0
  350. data/vendor/tomotopy/src/Labeling/Labeler.h +50 -0
  351. data/vendor/tomotopy/src/TopicModel/CT.h +37 -0
  352. data/vendor/tomotopy/src/TopicModel/CTModel.cpp +13 -0
  353. data/vendor/tomotopy/src/TopicModel/CTModel.hpp +293 -0
  354. data/vendor/tomotopy/src/TopicModel/DMR.h +51 -0
  355. data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +13 -0
  356. data/vendor/tomotopy/src/TopicModel/DMRModel.hpp +374 -0
  357. data/vendor/tomotopy/src/TopicModel/DT.h +65 -0
  358. data/vendor/tomotopy/src/TopicModel/DTM.h +22 -0
  359. data/vendor/tomotopy/src/TopicModel/DTModel.cpp +15 -0
  360. data/vendor/tomotopy/src/TopicModel/DTModel.hpp +572 -0
  361. data/vendor/tomotopy/src/TopicModel/GDMR.h +37 -0
  362. data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +14 -0
  363. data/vendor/tomotopy/src/TopicModel/GDMRModel.hpp +485 -0
  364. data/vendor/tomotopy/src/TopicModel/HDP.h +74 -0
  365. data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +13 -0
  366. data/vendor/tomotopy/src/TopicModel/HDPModel.hpp +592 -0
  367. data/vendor/tomotopy/src/TopicModel/HLDA.h +40 -0
  368. data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +13 -0
  369. data/vendor/tomotopy/src/TopicModel/HLDAModel.hpp +681 -0
  370. data/vendor/tomotopy/src/TopicModel/HPA.h +27 -0
  371. data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +21 -0
  372. data/vendor/tomotopy/src/TopicModel/HPAModel.hpp +588 -0
  373. data/vendor/tomotopy/src/TopicModel/LDA.h +144 -0
  374. data/vendor/tomotopy/src/TopicModel/LDACVB0Model.hpp +442 -0
  375. data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +13 -0
  376. data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +1058 -0
  377. data/vendor/tomotopy/src/TopicModel/LLDA.h +45 -0
  378. data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +13 -0
  379. data/vendor/tomotopy/src/TopicModel/LLDAModel.hpp +203 -0
  380. data/vendor/tomotopy/src/TopicModel/MGLDA.h +63 -0
  381. data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +17 -0
  382. data/vendor/tomotopy/src/TopicModel/MGLDAModel.hpp +558 -0
  383. data/vendor/tomotopy/src/TopicModel/PA.h +43 -0
  384. data/vendor/tomotopy/src/TopicModel/PAModel.cpp +13 -0
  385. data/vendor/tomotopy/src/TopicModel/PAModel.hpp +467 -0
  386. data/vendor/tomotopy/src/TopicModel/PLDA.h +17 -0
  387. data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +13 -0
  388. data/vendor/tomotopy/src/TopicModel/PLDAModel.hpp +214 -0
  389. data/vendor/tomotopy/src/TopicModel/SLDA.h +54 -0
  390. data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +17 -0
  391. data/vendor/tomotopy/src/TopicModel/SLDAModel.hpp +456 -0
  392. data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +692 -0
  393. data/vendor/tomotopy/src/Utils/AliasMethod.hpp +169 -0
  394. data/vendor/tomotopy/src/Utils/Dictionary.h +80 -0
  395. data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +181 -0
  396. data/vendor/tomotopy/src/Utils/LBFGS.h +202 -0
  397. data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBacktracking.h +120 -0
  398. data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBracketing.h +122 -0
  399. data/vendor/tomotopy/src/Utils/LBFGS/Param.h +213 -0
  400. data/vendor/tomotopy/src/Utils/LUT.hpp +82 -0
  401. data/vendor/tomotopy/src/Utils/MultiNormalDistribution.hpp +69 -0
  402. data/vendor/tomotopy/src/Utils/PolyaGamma.hpp +200 -0
  403. data/vendor/tomotopy/src/Utils/PolyaGammaHybrid.hpp +672 -0
  404. data/vendor/tomotopy/src/Utils/ThreadPool.hpp +150 -0
  405. data/vendor/tomotopy/src/Utils/Trie.hpp +220 -0
  406. data/vendor/tomotopy/src/Utils/TruncMultiNormal.hpp +94 -0
  407. data/vendor/tomotopy/src/Utils/Utils.hpp +337 -0
  408. data/vendor/tomotopy/src/Utils/avx_gamma.h +46 -0
  409. data/vendor/tomotopy/src/Utils/avx_mathfun.h +736 -0
  410. data/vendor/tomotopy/src/Utils/exception.h +28 -0
  411. data/vendor/tomotopy/src/Utils/math.h +281 -0
  412. data/vendor/tomotopy/src/Utils/rtnorm.hpp +2690 -0
  413. data/vendor/tomotopy/src/Utils/sample.hpp +192 -0
  414. data/vendor/tomotopy/src/Utils/serializer.hpp +695 -0
  415. data/vendor/tomotopy/src/Utils/slp.hpp +131 -0
  416. data/vendor/tomotopy/src/Utils/sse_gamma.h +48 -0
  417. data/vendor/tomotopy/src/Utils/sse_mathfun.h +710 -0
  418. data/vendor/tomotopy/src/Utils/text.hpp +49 -0
  419. data/vendor/tomotopy/src/Utils/tvector.hpp +543 -0
  420. metadata +531 -0
@@ -0,0 +1,415 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5
+ // Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
6
+ //
7
+ // This Source Code Form is subject to the terms of the Mozilla
8
+ // Public License v. 2.0. If a copy of the MPL was not distributed
9
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
+
11
+ #ifndef EIGEN_INVERSE_IMPL_H
12
+ #define EIGEN_INVERSE_IMPL_H
13
+
14
+ namespace Eigen {
15
+
16
+ namespace internal {
17
+
18
+ /**********************************
19
+ *** General case implementation ***
20
+ **********************************/
21
+
22
+ template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
23
+ struct compute_inverse
24
+ {
25
+ EIGEN_DEVICE_FUNC
26
+ static inline void run(const MatrixType& matrix, ResultType& result)
27
+ {
28
+ result = matrix.partialPivLu().inverse();
29
+ }
30
+ };
31
+
32
+ template<typename MatrixType, typename ResultType, int Size = MatrixType::RowsAtCompileTime>
33
+ struct compute_inverse_and_det_with_check { /* nothing! general case not supported. */ };
34
+
35
+ /****************************
36
+ *** Size 1 implementation ***
37
+ ****************************/
38
+
39
+ template<typename MatrixType, typename ResultType>
40
+ struct compute_inverse<MatrixType, ResultType, 1>
41
+ {
42
+ EIGEN_DEVICE_FUNC
43
+ static inline void run(const MatrixType& matrix, ResultType& result)
44
+ {
45
+ typedef typename MatrixType::Scalar Scalar;
46
+ internal::evaluator<MatrixType> matrixEval(matrix);
47
+ result.coeffRef(0,0) = Scalar(1) / matrixEval.coeff(0,0);
48
+ }
49
+ };
50
+
51
+ template<typename MatrixType, typename ResultType>
52
+ struct compute_inverse_and_det_with_check<MatrixType, ResultType, 1>
53
+ {
54
+ EIGEN_DEVICE_FUNC
55
+ static inline void run(
56
+ const MatrixType& matrix,
57
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
58
+ ResultType& result,
59
+ typename ResultType::Scalar& determinant,
60
+ bool& invertible
61
+ )
62
+ {
63
+ using std::abs;
64
+ determinant = matrix.coeff(0,0);
65
+ invertible = abs(determinant) > absDeterminantThreshold;
66
+ if(invertible) result.coeffRef(0,0) = typename ResultType::Scalar(1) / determinant;
67
+ }
68
+ };
69
+
70
+ /****************************
71
+ *** Size 2 implementation ***
72
+ ****************************/
73
+
74
+ template<typename MatrixType, typename ResultType>
75
+ EIGEN_DEVICE_FUNC
76
+ inline void compute_inverse_size2_helper(
77
+ const MatrixType& matrix, const typename ResultType::Scalar& invdet,
78
+ ResultType& result)
79
+ {
80
+ result.coeffRef(0,0) = matrix.coeff(1,1) * invdet;
81
+ result.coeffRef(1,0) = -matrix.coeff(1,0) * invdet;
82
+ result.coeffRef(0,1) = -matrix.coeff(0,1) * invdet;
83
+ result.coeffRef(1,1) = matrix.coeff(0,0) * invdet;
84
+ }
85
+
86
+ template<typename MatrixType, typename ResultType>
87
+ struct compute_inverse<MatrixType, ResultType, 2>
88
+ {
89
+ EIGEN_DEVICE_FUNC
90
+ static inline void run(const MatrixType& matrix, ResultType& result)
91
+ {
92
+ typedef typename ResultType::Scalar Scalar;
93
+ const Scalar invdet = typename MatrixType::Scalar(1) / matrix.determinant();
94
+ compute_inverse_size2_helper(matrix, invdet, result);
95
+ }
96
+ };
97
+
98
+ template<typename MatrixType, typename ResultType>
99
+ struct compute_inverse_and_det_with_check<MatrixType, ResultType, 2>
100
+ {
101
+ EIGEN_DEVICE_FUNC
102
+ static inline void run(
103
+ const MatrixType& matrix,
104
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
105
+ ResultType& inverse,
106
+ typename ResultType::Scalar& determinant,
107
+ bool& invertible
108
+ )
109
+ {
110
+ using std::abs;
111
+ typedef typename ResultType::Scalar Scalar;
112
+ determinant = matrix.determinant();
113
+ invertible = abs(determinant) > absDeterminantThreshold;
114
+ if(!invertible) return;
115
+ const Scalar invdet = Scalar(1) / determinant;
116
+ compute_inverse_size2_helper(matrix, invdet, inverse);
117
+ }
118
+ };
119
+
120
+ /****************************
121
+ *** Size 3 implementation ***
122
+ ****************************/
123
+
124
+ template<typename MatrixType, int i, int j>
125
+ EIGEN_DEVICE_FUNC
126
+ inline typename MatrixType::Scalar cofactor_3x3(const MatrixType& m)
127
+ {
128
+ enum {
129
+ i1 = (i+1) % 3,
130
+ i2 = (i+2) % 3,
131
+ j1 = (j+1) % 3,
132
+ j2 = (j+2) % 3
133
+ };
134
+ return m.coeff(i1, j1) * m.coeff(i2, j2)
135
+ - m.coeff(i1, j2) * m.coeff(i2, j1);
136
+ }
137
+
138
+ template<typename MatrixType, typename ResultType>
139
+ EIGEN_DEVICE_FUNC
140
+ inline void compute_inverse_size3_helper(
141
+ const MatrixType& matrix,
142
+ const typename ResultType::Scalar& invdet,
143
+ const Matrix<typename ResultType::Scalar,3,1>& cofactors_col0,
144
+ ResultType& result)
145
+ {
146
+ result.row(0) = cofactors_col0 * invdet;
147
+ result.coeffRef(1,0) = cofactor_3x3<MatrixType,0,1>(matrix) * invdet;
148
+ result.coeffRef(1,1) = cofactor_3x3<MatrixType,1,1>(matrix) * invdet;
149
+ result.coeffRef(1,2) = cofactor_3x3<MatrixType,2,1>(matrix) * invdet;
150
+ result.coeffRef(2,0) = cofactor_3x3<MatrixType,0,2>(matrix) * invdet;
151
+ result.coeffRef(2,1) = cofactor_3x3<MatrixType,1,2>(matrix) * invdet;
152
+ result.coeffRef(2,2) = cofactor_3x3<MatrixType,2,2>(matrix) * invdet;
153
+ }
154
+
155
+ template<typename MatrixType, typename ResultType>
156
+ struct compute_inverse<MatrixType, ResultType, 3>
157
+ {
158
+ EIGEN_DEVICE_FUNC
159
+ static inline void run(const MatrixType& matrix, ResultType& result)
160
+ {
161
+ typedef typename ResultType::Scalar Scalar;
162
+ Matrix<typename MatrixType::Scalar,3,1> cofactors_col0;
163
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
164
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
165
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
166
+ const Scalar det = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
167
+ const Scalar invdet = Scalar(1) / det;
168
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, result);
169
+ }
170
+ };
171
+
172
+ template<typename MatrixType, typename ResultType>
173
+ struct compute_inverse_and_det_with_check<MatrixType, ResultType, 3>
174
+ {
175
+ EIGEN_DEVICE_FUNC
176
+ static inline void run(
177
+ const MatrixType& matrix,
178
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
179
+ ResultType& inverse,
180
+ typename ResultType::Scalar& determinant,
181
+ bool& invertible
182
+ )
183
+ {
184
+ using std::abs;
185
+ typedef typename ResultType::Scalar Scalar;
186
+ Matrix<Scalar,3,1> cofactors_col0;
187
+ cofactors_col0.coeffRef(0) = cofactor_3x3<MatrixType,0,0>(matrix);
188
+ cofactors_col0.coeffRef(1) = cofactor_3x3<MatrixType,1,0>(matrix);
189
+ cofactors_col0.coeffRef(2) = cofactor_3x3<MatrixType,2,0>(matrix);
190
+ determinant = (cofactors_col0.cwiseProduct(matrix.col(0))).sum();
191
+ invertible = abs(determinant) > absDeterminantThreshold;
192
+ if(!invertible) return;
193
+ const Scalar invdet = Scalar(1) / determinant;
194
+ compute_inverse_size3_helper(matrix, invdet, cofactors_col0, inverse);
195
+ }
196
+ };
197
+
198
+ /****************************
199
+ *** Size 4 implementation ***
200
+ ****************************/
201
+
202
+ template<typename Derived>
203
+ EIGEN_DEVICE_FUNC
204
+ inline const typename Derived::Scalar general_det3_helper
205
+ (const MatrixBase<Derived>& matrix, int i1, int i2, int i3, int j1, int j2, int j3)
206
+ {
207
+ return matrix.coeff(i1,j1)
208
+ * (matrix.coeff(i2,j2) * matrix.coeff(i3,j3) - matrix.coeff(i2,j3) * matrix.coeff(i3,j2));
209
+ }
210
+
211
+ template<typename MatrixType, int i, int j>
212
+ EIGEN_DEVICE_FUNC
213
+ inline typename MatrixType::Scalar cofactor_4x4(const MatrixType& matrix)
214
+ {
215
+ enum {
216
+ i1 = (i+1) % 4,
217
+ i2 = (i+2) % 4,
218
+ i3 = (i+3) % 4,
219
+ j1 = (j+1) % 4,
220
+ j2 = (j+2) % 4,
221
+ j3 = (j+3) % 4
222
+ };
223
+ return general_det3_helper(matrix, i1, i2, i3, j1, j2, j3)
224
+ + general_det3_helper(matrix, i2, i3, i1, j1, j2, j3)
225
+ + general_det3_helper(matrix, i3, i1, i2, j1, j2, j3);
226
+ }
227
+
228
+ template<int Arch, typename Scalar, typename MatrixType, typename ResultType>
229
+ struct compute_inverse_size4
230
+ {
231
+ EIGEN_DEVICE_FUNC
232
+ static void run(const MatrixType& matrix, ResultType& result)
233
+ {
234
+ result.coeffRef(0,0) = cofactor_4x4<MatrixType,0,0>(matrix);
235
+ result.coeffRef(1,0) = -cofactor_4x4<MatrixType,0,1>(matrix);
236
+ result.coeffRef(2,0) = cofactor_4x4<MatrixType,0,2>(matrix);
237
+ result.coeffRef(3,0) = -cofactor_4x4<MatrixType,0,3>(matrix);
238
+ result.coeffRef(0,2) = cofactor_4x4<MatrixType,2,0>(matrix);
239
+ result.coeffRef(1,2) = -cofactor_4x4<MatrixType,2,1>(matrix);
240
+ result.coeffRef(2,2) = cofactor_4x4<MatrixType,2,2>(matrix);
241
+ result.coeffRef(3,2) = -cofactor_4x4<MatrixType,2,3>(matrix);
242
+ result.coeffRef(0,1) = -cofactor_4x4<MatrixType,1,0>(matrix);
243
+ result.coeffRef(1,1) = cofactor_4x4<MatrixType,1,1>(matrix);
244
+ result.coeffRef(2,1) = -cofactor_4x4<MatrixType,1,2>(matrix);
245
+ result.coeffRef(3,1) = cofactor_4x4<MatrixType,1,3>(matrix);
246
+ result.coeffRef(0,3) = -cofactor_4x4<MatrixType,3,0>(matrix);
247
+ result.coeffRef(1,3) = cofactor_4x4<MatrixType,3,1>(matrix);
248
+ result.coeffRef(2,3) = -cofactor_4x4<MatrixType,3,2>(matrix);
249
+ result.coeffRef(3,3) = cofactor_4x4<MatrixType,3,3>(matrix);
250
+ result /= (matrix.col(0).cwiseProduct(result.row(0).transpose())).sum();
251
+ }
252
+ };
253
+
254
+ template<typename MatrixType, typename ResultType>
255
+ struct compute_inverse<MatrixType, ResultType, 4>
256
+ : compute_inverse_size4<Architecture::Target, typename MatrixType::Scalar,
257
+ MatrixType, ResultType>
258
+ {
259
+ };
260
+
261
+ template<typename MatrixType, typename ResultType>
262
+ struct compute_inverse_and_det_with_check<MatrixType, ResultType, 4>
263
+ {
264
+ EIGEN_DEVICE_FUNC
265
+ static inline void run(
266
+ const MatrixType& matrix,
267
+ const typename MatrixType::RealScalar& absDeterminantThreshold,
268
+ ResultType& inverse,
269
+ typename ResultType::Scalar& determinant,
270
+ bool& invertible
271
+ )
272
+ {
273
+ using std::abs;
274
+ determinant = matrix.determinant();
275
+ invertible = abs(determinant) > absDeterminantThreshold;
276
+ if(invertible) compute_inverse<MatrixType, ResultType>::run(matrix, inverse);
277
+ }
278
+ };
279
+
280
+ /*************************
281
+ *** MatrixBase methods ***
282
+ *************************/
283
+
284
+ } // end namespace internal
285
+
286
+ namespace internal {
287
+
288
+ // Specialization for "dense = dense_xpr.inverse()"
289
+ template<typename DstXprType, typename XprType>
290
+ struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar>, Dense2Dense>
291
+ {
292
+ typedef Inverse<XprType> SrcXprType;
293
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename XprType::Scalar> &)
294
+ {
295
+ Index dstRows = src.rows();
296
+ Index dstCols = src.cols();
297
+ if((dst.rows()!=dstRows) || (dst.cols()!=dstCols))
298
+ dst.resize(dstRows, dstCols);
299
+
300
+ const int Size = EIGEN_PLAIN_ENUM_MIN(XprType::ColsAtCompileTime,DstXprType::ColsAtCompileTime);
301
+ EIGEN_ONLY_USED_FOR_DEBUG(Size);
302
+ eigen_assert(( (Size<=1) || (Size>4) || (extract_data(src.nestedExpression())!=extract_data(dst)))
303
+ && "Aliasing problem detected in inverse(), you need to do inverse().eval() here.");
304
+
305
+ typedef typename internal::nested_eval<XprType,XprType::ColsAtCompileTime>::type ActualXprType;
306
+ typedef typename internal::remove_all<ActualXprType>::type ActualXprTypeCleanded;
307
+
308
+ ActualXprType actual_xpr(src.nestedExpression());
309
+
310
+ compute_inverse<ActualXprTypeCleanded, DstXprType>::run(actual_xpr, dst);
311
+ }
312
+ };
313
+
314
+
315
+ } // end namespace internal
316
+
317
+ /** \lu_module
318
+ *
319
+ * \returns the matrix inverse of this matrix.
320
+ *
321
+ * For small fixed sizes up to 4x4, this method uses cofactors.
322
+ * In the general case, this method uses class PartialPivLU.
323
+ *
324
+ * \note This matrix must be invertible, otherwise the result is undefined. If you need an
325
+ * invertibility check, do the following:
326
+ * \li for fixed sizes up to 4x4, use computeInverseAndDetWithCheck().
327
+ * \li for the general case, use class FullPivLU.
328
+ *
329
+ * Example: \include MatrixBase_inverse.cpp
330
+ * Output: \verbinclude MatrixBase_inverse.out
331
+ *
332
+ * \sa computeInverseAndDetWithCheck()
333
+ */
334
+ template<typename Derived>
335
+ inline const Inverse<Derived> MatrixBase<Derived>::inverse() const
336
+ {
337
+ EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsInteger,THIS_FUNCTION_IS_NOT_FOR_INTEGER_NUMERIC_TYPES)
338
+ eigen_assert(rows() == cols());
339
+ return Inverse<Derived>(derived());
340
+ }
341
+
342
+ /** \lu_module
343
+ *
344
+ * Computation of matrix inverse and determinant, with invertibility check.
345
+ *
346
+ * This is only for fixed-size square matrices of size up to 4x4.
347
+ *
348
+ * \param inverse Reference to the matrix in which to store the inverse.
349
+ * \param determinant Reference to the variable in which to store the determinant.
350
+ * \param invertible Reference to the bool variable in which to store whether the matrix is invertible.
351
+ * \param absDeterminantThreshold Optional parameter controlling the invertibility check.
352
+ * The matrix will be declared invertible if the absolute value of its
353
+ * determinant is greater than this threshold.
354
+ *
355
+ * Example: \include MatrixBase_computeInverseAndDetWithCheck.cpp
356
+ * Output: \verbinclude MatrixBase_computeInverseAndDetWithCheck.out
357
+ *
358
+ * \sa inverse(), computeInverseWithCheck()
359
+ */
360
+ template<typename Derived>
361
+ template<typename ResultType>
362
+ inline void MatrixBase<Derived>::computeInverseAndDetWithCheck(
363
+ ResultType& inverse,
364
+ typename ResultType::Scalar& determinant,
365
+ bool& invertible,
366
+ const RealScalar& absDeterminantThreshold
367
+ ) const
368
+ {
369
+ // i'd love to put some static assertions there, but SFINAE means that they have no effect...
370
+ eigen_assert(rows() == cols());
371
+ // for 2x2, it's worth giving a chance to avoid evaluating.
372
+ // for larger sizes, evaluating has negligible cost and limits code size.
373
+ typedef typename internal::conditional<
374
+ RowsAtCompileTime == 2,
375
+ typename internal::remove_all<typename internal::nested_eval<Derived, 2>::type>::type,
376
+ PlainObject
377
+ >::type MatrixType;
378
+ internal::compute_inverse_and_det_with_check<MatrixType, ResultType>::run
379
+ (derived(), absDeterminantThreshold, inverse, determinant, invertible);
380
+ }
381
+
382
+ /** \lu_module
383
+ *
384
+ * Computation of matrix inverse, with invertibility check.
385
+ *
386
+ * This is only for fixed-size square matrices of size up to 4x4.
387
+ *
388
+ * \param inverse Reference to the matrix in which to store the inverse.
389
+ * \param invertible Reference to the bool variable in which to store whether the matrix is invertible.
390
+ * \param absDeterminantThreshold Optional parameter controlling the invertibility check.
391
+ * The matrix will be declared invertible if the absolute value of its
392
+ * determinant is greater than this threshold.
393
+ *
394
+ * Example: \include MatrixBase_computeInverseWithCheck.cpp
395
+ * Output: \verbinclude MatrixBase_computeInverseWithCheck.out
396
+ *
397
+ * \sa inverse(), computeInverseAndDetWithCheck()
398
+ */
399
+ template<typename Derived>
400
+ template<typename ResultType>
401
+ inline void MatrixBase<Derived>::computeInverseWithCheck(
402
+ ResultType& inverse,
403
+ bool& invertible,
404
+ const RealScalar& absDeterminantThreshold
405
+ ) const
406
+ {
407
+ Scalar determinant;
408
+ // i'd love to put some static assertions there, but SFINAE means that they have no effect...
409
+ eigen_assert(rows() == cols());
410
+ computeInverseAndDetWithCheck(inverse,determinant,invertible,absDeterminantThreshold);
411
+ }
412
+
413
+ } // end namespace Eigen
414
+
415
+ #endif // EIGEN_INVERSE_IMPL_H
@@ -0,0 +1,611 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
5
+ // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6
+ //
7
+ // This Source Code Form is subject to the terms of the Mozilla
8
+ // Public License v. 2.0. If a copy of the MPL was not distributed
9
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
+
11
+ #ifndef EIGEN_PARTIALLU_H
12
+ #define EIGEN_PARTIALLU_H
13
+
14
+ namespace Eigen {
15
+
16
+ namespace internal {
17
+ template<typename _MatrixType> struct traits<PartialPivLU<_MatrixType> >
18
+ : traits<_MatrixType>
19
+ {
20
+ typedef MatrixXpr XprKind;
21
+ typedef SolverStorage StorageKind;
22
+ typedef traits<_MatrixType> BaseTraits;
23
+ enum {
24
+ Flags = BaseTraits::Flags & RowMajorBit,
25
+ CoeffReadCost = Dynamic
26
+ };
27
+ };
28
+
29
+ template<typename T,typename Derived>
30
+ struct enable_if_ref;
31
+ // {
32
+ // typedef Derived type;
33
+ // };
34
+
35
+ template<typename T,typename Derived>
36
+ struct enable_if_ref<Ref<T>,Derived> {
37
+ typedef Derived type;
38
+ };
39
+
40
+ } // end namespace internal
41
+
42
+ /** \ingroup LU_Module
43
+ *
44
+ * \class PartialPivLU
45
+ *
46
+ * \brief LU decomposition of a matrix with partial pivoting, and related features
47
+ *
48
+ * \tparam _MatrixType the type of the matrix of which we are computing the LU decomposition
49
+ *
50
+ * This class represents a LU decomposition of a \b square \b invertible matrix, with partial pivoting: the matrix A
51
+ * is decomposed as A = PLU where L is unit-lower-triangular, U is upper-triangular, and P
52
+ * is a permutation matrix.
53
+ *
54
+ * Typically, partial pivoting LU decomposition is only considered numerically stable for square invertible
55
+ * matrices. Thus LAPACK's dgesv and dgesvx require the matrix to be square and invertible. The present class
56
+ * does the same. It will assert that the matrix is square, but it won't (actually it can't) check that the
57
+ * matrix is invertible: it is your task to check that you only use this decomposition on invertible matrices.
58
+ *
59
+ * The guaranteed safe alternative, working for all matrices, is the full pivoting LU decomposition, provided
60
+ * by class FullPivLU.
61
+ *
62
+ * This is \b not a rank-revealing LU decomposition. Many features are intentionally absent from this class,
63
+ * such as rank computation. If you need these features, use class FullPivLU.
64
+ *
65
+ * This LU decomposition is suitable to invert invertible matrices. It is what MatrixBase::inverse() uses
66
+ * in the general case.
67
+ * On the other hand, it is \b not suitable to determine whether a given matrix is invertible.
68
+ *
69
+ * The data of the LU decomposition can be directly accessed through the methods matrixLU(), permutationP().
70
+ *
71
+ * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
72
+ *
73
+ * \sa MatrixBase::partialPivLu(), MatrixBase::determinant(), MatrixBase::inverse(), MatrixBase::computeInverse(), class FullPivLU
74
+ */
75
+ template<typename _MatrixType> class PartialPivLU
76
+ : public SolverBase<PartialPivLU<_MatrixType> >
77
+ {
78
+ public:
79
+
80
+ typedef _MatrixType MatrixType;
81
+ typedef SolverBase<PartialPivLU> Base;
82
+ EIGEN_GENERIC_PUBLIC_INTERFACE(PartialPivLU)
83
+ // FIXME StorageIndex defined in EIGEN_GENERIC_PUBLIC_INTERFACE should be int
84
+ enum {
85
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
86
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
87
+ };
88
+ typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType;
89
+ typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType;
90
+ typedef typename MatrixType::PlainObject PlainObject;
91
+
92
+ /**
93
+ * \brief Default Constructor.
94
+ *
95
+ * The default constructor is useful in cases in which the user intends to
96
+ * perform decompositions via PartialPivLU::compute(const MatrixType&).
97
+ */
98
+ PartialPivLU();
99
+
100
+ /** \brief Default Constructor with memory preallocation
101
+ *
102
+ * Like the default constructor but with preallocation of the internal data
103
+ * according to the specified problem \a size.
104
+ * \sa PartialPivLU()
105
+ */
106
+ explicit PartialPivLU(Index size);
107
+
108
+ /** Constructor.
109
+ *
110
+ * \param matrix the matrix of which to compute the LU decomposition.
111
+ *
112
+ * \warning The matrix should have full rank (e.g. if it's square, it should be invertible).
113
+ * If you need to deal with non-full rank, use class FullPivLU instead.
114
+ */
115
+ template<typename InputType>
116
+ explicit PartialPivLU(const EigenBase<InputType>& matrix);
117
+
118
+ /** Constructor for \link InplaceDecomposition inplace decomposition \endlink
119
+ *
120
+ * \param matrix the matrix of which to compute the LU decomposition.
121
+ *
122
+ * \warning The matrix should have full rank (e.g. if it's square, it should be invertible).
123
+ * If you need to deal with non-full rank, use class FullPivLU instead.
124
+ */
125
+ template<typename InputType>
126
+ explicit PartialPivLU(EigenBase<InputType>& matrix);
127
+
128
+ template<typename InputType>
129
+ PartialPivLU& compute(const EigenBase<InputType>& matrix) {
130
+ m_lu = matrix.derived();
131
+ compute();
132
+ return *this;
133
+ }
134
+
135
+ /** \returns the LU decomposition matrix: the upper-triangular part is U, the
136
+ * unit-lower-triangular part is L (at least for square matrices; in the non-square
137
+ * case, special care is needed, see the documentation of class FullPivLU).
138
+ *
139
+ * \sa matrixL(), matrixU()
140
+ */
141
+ inline const MatrixType& matrixLU() const
142
+ {
143
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
144
+ return m_lu;
145
+ }
146
+
147
+ /** \returns the permutation matrix P.
148
+ */
149
+ inline const PermutationType& permutationP() const
150
+ {
151
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
152
+ return m_p;
153
+ }
154
+
155
+ /** This method returns the solution x to the equation Ax=b, where A is the matrix of which
156
+ * *this is the LU decomposition.
157
+ *
158
+ * \param b the right-hand-side of the equation to solve. Can be a vector or a matrix,
159
+ * the only requirement in order for the equation to make sense is that
160
+ * b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition.
161
+ *
162
+ * \returns the solution.
163
+ *
164
+ * Example: \include PartialPivLU_solve.cpp
165
+ * Output: \verbinclude PartialPivLU_solve.out
166
+ *
167
+ * Since this PartialPivLU class assumes anyway that the matrix A is invertible, the solution
168
+ * theoretically exists and is unique regardless of b.
169
+ *
170
+ * \sa TriangularView::solve(), inverse(), computeInverse()
171
+ */
172
+ // FIXME this is a copy-paste of the base-class member to add the isInitialized assertion.
173
+ template<typename Rhs>
174
+ inline const Solve<PartialPivLU, Rhs>
175
+ solve(const MatrixBase<Rhs>& b) const
176
+ {
177
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
178
+ return Solve<PartialPivLU, Rhs>(*this, b.derived());
179
+ }
180
+
181
+ /** \returns an estimate of the reciprocal condition number of the matrix of which \c *this is
182
+ the LU decomposition.
183
+ */
184
+ inline RealScalar rcond() const
185
+ {
186
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
187
+ return internal::rcond_estimate_helper(m_l1_norm, *this);
188
+ }
189
+
190
+ /** \returns the inverse of the matrix of which *this is the LU decomposition.
191
+ *
192
+ * \warning The matrix being decomposed here is assumed to be invertible. If you need to check for
193
+ * invertibility, use class FullPivLU instead.
194
+ *
195
+ * \sa MatrixBase::inverse(), LU::inverse()
196
+ */
197
+ inline const Inverse<PartialPivLU> inverse() const
198
+ {
199
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
200
+ return Inverse<PartialPivLU>(*this);
201
+ }
202
+
203
+ /** \returns the determinant of the matrix of which
204
+ * *this is the LU decomposition. It has only linear complexity
205
+ * (that is, O(n) where n is the dimension of the square matrix)
206
+ * as the LU decomposition has already been computed.
207
+ *
208
+ * \note For fixed-size matrices of size up to 4, MatrixBase::determinant() offers
209
+ * optimized paths.
210
+ *
211
+ * \warning a determinant can be very big or small, so for matrices
212
+ * of large enough dimension, there is a risk of overflow/underflow.
213
+ *
214
+ * \sa MatrixBase::determinant()
215
+ */
216
+ Scalar determinant() const;
217
+
218
+ MatrixType reconstructedMatrix() const;
219
+
220
+ inline Index rows() const { return m_lu.rows(); }
221
+ inline Index cols() const { return m_lu.cols(); }
222
+
223
+ #ifndef EIGEN_PARSED_BY_DOXYGEN
224
+ template<typename RhsType, typename DstType>
225
+ EIGEN_DEVICE_FUNC
226
+ void _solve_impl(const RhsType &rhs, DstType &dst) const {
227
+ /* The decomposition PA = LU can be rewritten as A = P^{-1} L U.
228
+ * So we proceed as follows:
229
+ * Step 1: compute c = Pb.
230
+ * Step 2: replace c by the solution x to Lx = c.
231
+ * Step 3: replace c by the solution x to Ux = c.
232
+ */
233
+
234
+ eigen_assert(rhs.rows() == m_lu.rows());
235
+
236
+ // Step 1
237
+ dst = permutationP() * rhs;
238
+
239
+ // Step 2
240
+ m_lu.template triangularView<UnitLower>().solveInPlace(dst);
241
+
242
+ // Step 3
243
+ m_lu.template triangularView<Upper>().solveInPlace(dst);
244
+ }
245
+
246
+ template<bool Conjugate, typename RhsType, typename DstType>
247
+ EIGEN_DEVICE_FUNC
248
+ void _solve_impl_transposed(const RhsType &rhs, DstType &dst) const {
249
+ /* The decomposition PA = LU can be rewritten as A = P^{-1} L U.
250
+ * So we proceed as follows:
251
+ * Step 1: compute c = Pb.
252
+ * Step 2: replace c by the solution x to Lx = c.
253
+ * Step 3: replace c by the solution x to Ux = c.
254
+ */
255
+
256
+ eigen_assert(rhs.rows() == m_lu.cols());
257
+
258
+ if (Conjugate) {
259
+ // Step 1
260
+ dst = m_lu.template triangularView<Upper>().adjoint().solve(rhs);
261
+ // Step 2
262
+ m_lu.template triangularView<UnitLower>().adjoint().solveInPlace(dst);
263
+ } else {
264
+ // Step 1
265
+ dst = m_lu.template triangularView<Upper>().transpose().solve(rhs);
266
+ // Step 2
267
+ m_lu.template triangularView<UnitLower>().transpose().solveInPlace(dst);
268
+ }
269
+ // Step 3
270
+ dst = permutationP().transpose() * dst;
271
+ }
272
+ #endif
273
+
274
+ protected:
275
+
276
+ static void check_template_parameters()
277
+ {
278
+ EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
279
+ }
280
+
281
+ void compute();
282
+
283
+ MatrixType m_lu;
284
+ PermutationType m_p;
285
+ TranspositionType m_rowsTranspositions;
286
+ RealScalar m_l1_norm;
287
+ signed char m_det_p;
288
+ bool m_isInitialized;
289
+ };
290
+
291
+ template<typename MatrixType>
292
+ PartialPivLU<MatrixType>::PartialPivLU()
293
+ : m_lu(),
294
+ m_p(),
295
+ m_rowsTranspositions(),
296
+ m_l1_norm(0),
297
+ m_det_p(0),
298
+ m_isInitialized(false)
299
+ {
300
+ }
301
+
302
+ template<typename MatrixType>
303
+ PartialPivLU<MatrixType>::PartialPivLU(Index size)
304
+ : m_lu(size, size),
305
+ m_p(size),
306
+ m_rowsTranspositions(size),
307
+ m_l1_norm(0),
308
+ m_det_p(0),
309
+ m_isInitialized(false)
310
+ {
311
+ }
312
+
313
+ template<typename MatrixType>
314
+ template<typename InputType>
315
+ PartialPivLU<MatrixType>::PartialPivLU(const EigenBase<InputType>& matrix)
316
+ : m_lu(matrix.rows(),matrix.cols()),
317
+ m_p(matrix.rows()),
318
+ m_rowsTranspositions(matrix.rows()),
319
+ m_l1_norm(0),
320
+ m_det_p(0),
321
+ m_isInitialized(false)
322
+ {
323
+ compute(matrix.derived());
324
+ }
325
+
326
+ template<typename MatrixType>
327
+ template<typename InputType>
328
+ PartialPivLU<MatrixType>::PartialPivLU(EigenBase<InputType>& matrix)
329
+ : m_lu(matrix.derived()),
330
+ m_p(matrix.rows()),
331
+ m_rowsTranspositions(matrix.rows()),
332
+ m_l1_norm(0),
333
+ m_det_p(0),
334
+ m_isInitialized(false)
335
+ {
336
+ compute();
337
+ }
338
+
339
+ namespace internal {
340
+
341
+ /** \internal This is the blocked version of fullpivlu_unblocked() */
342
+ template<typename Scalar, int StorageOrder, typename PivIndex>
343
+ struct partial_lu_impl
344
+ {
345
+ // FIXME add a stride to Map, so that the following mapping becomes easier,
346
+ // another option would be to create an expression being able to automatically
347
+ // warp any Map, Matrix, and Block expressions as a unique type, but since that's exactly
348
+ // a Map + stride, why not adding a stride to Map, and convenient ctors from a Matrix,
349
+ // and Block.
350
+ typedef Map<Matrix<Scalar, Dynamic, Dynamic, StorageOrder> > MapLU;
351
+ typedef Block<MapLU, Dynamic, Dynamic> MatrixType;
352
+ typedef Block<MatrixType,Dynamic,Dynamic> BlockType;
353
+ typedef typename MatrixType::RealScalar RealScalar;
354
+
355
+ /** \internal performs the LU decomposition in-place of the matrix \a lu
356
+ * using an unblocked algorithm.
357
+ *
358
+ * In addition, this function returns the row transpositions in the
359
+ * vector \a row_transpositions which must have a size equal to the number
360
+ * of columns of the matrix \a lu, and an integer \a nb_transpositions
361
+ * which returns the actual number of transpositions.
362
+ *
363
+ * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise.
364
+ */
365
+ static Index unblocked_lu(MatrixType& lu, PivIndex* row_transpositions, PivIndex& nb_transpositions)
366
+ {
367
+ typedef scalar_score_coeff_op<Scalar> Scoring;
368
+ typedef typename Scoring::result_type Score;
369
+ const Index rows = lu.rows();
370
+ const Index cols = lu.cols();
371
+ const Index size = (std::min)(rows,cols);
372
+ nb_transpositions = 0;
373
+ Index first_zero_pivot = -1;
374
+ for(Index k = 0; k < size; ++k)
375
+ {
376
+ Index rrows = rows-k-1;
377
+ Index rcols = cols-k-1;
378
+
379
+ Index row_of_biggest_in_col;
380
+ Score biggest_in_corner
381
+ = lu.col(k).tail(rows-k).unaryExpr(Scoring()).maxCoeff(&row_of_biggest_in_col);
382
+ row_of_biggest_in_col += k;
383
+
384
+ row_transpositions[k] = PivIndex(row_of_biggest_in_col);
385
+
386
+ if(biggest_in_corner != Score(0))
387
+ {
388
+ if(k != row_of_biggest_in_col)
389
+ {
390
+ lu.row(k).swap(lu.row(row_of_biggest_in_col));
391
+ ++nb_transpositions;
392
+ }
393
+
394
+ // FIXME shall we introduce a safe quotient expression in cas 1/lu.coeff(k,k)
395
+ // overflow but not the actual quotient?
396
+ lu.col(k).tail(rrows) /= lu.coeff(k,k);
397
+ }
398
+ else if(first_zero_pivot==-1)
399
+ {
400
+ // the pivot is exactly zero, we record the index of the first pivot which is exactly 0,
401
+ // and continue the factorization such we still have A = PLU
402
+ first_zero_pivot = k;
403
+ }
404
+
405
+ if(k<rows-1)
406
+ lu.bottomRightCorner(rrows,rcols).noalias() -= lu.col(k).tail(rrows) * lu.row(k).tail(rcols);
407
+ }
408
+ return first_zero_pivot;
409
+ }
410
+
411
+ /** \internal performs the LU decomposition in-place of the matrix represented
412
+ * by the variables \a rows, \a cols, \a lu_data, and \a lu_stride using a
413
+ * recursive, blocked algorithm.
414
+ *
415
+ * In addition, this function returns the row transpositions in the
416
+ * vector \a row_transpositions which must have a size equal to the number
417
+ * of columns of the matrix \a lu, and an integer \a nb_transpositions
418
+ * which returns the actual number of transpositions.
419
+ *
420
+ * \returns The index of the first pivot which is exactly zero if any, or a negative number otherwise.
421
+ *
422
+ * \note This very low level interface using pointers, etc. is to:
423
+ * 1 - reduce the number of instanciations to the strict minimum
424
+ * 2 - avoid infinite recursion of the instanciations with Block<Block<Block<...> > >
425
+ */
426
+ static Index blocked_lu(Index rows, Index cols, Scalar* lu_data, Index luStride, PivIndex* row_transpositions, PivIndex& nb_transpositions, Index maxBlockSize=256)
427
+ {
428
+ MapLU lu1(lu_data,StorageOrder==RowMajor?rows:luStride,StorageOrder==RowMajor?luStride:cols);
429
+ MatrixType lu(lu1,0,0,rows,cols);
430
+
431
+ const Index size = (std::min)(rows,cols);
432
+
433
+ // if the matrix is too small, no blocking:
434
+ if(size<=16)
435
+ {
436
+ return unblocked_lu(lu, row_transpositions, nb_transpositions);
437
+ }
438
+
439
+ // automatically adjust the number of subdivisions to the size
440
+ // of the matrix so that there is enough sub blocks:
441
+ Index blockSize;
442
+ {
443
+ blockSize = size/8;
444
+ blockSize = (blockSize/16)*16;
445
+ blockSize = (std::min)((std::max)(blockSize,Index(8)), maxBlockSize);
446
+ }
447
+
448
+ nb_transpositions = 0;
449
+ Index first_zero_pivot = -1;
450
+ for(Index k = 0; k < size; k+=blockSize)
451
+ {
452
+ Index bs = (std::min)(size-k,blockSize); // actual size of the block
453
+ Index trows = rows - k - bs; // trailing rows
454
+ Index tsize = size - k - bs; // trailing size
455
+
456
+ // partition the matrix:
457
+ // A00 | A01 | A02
458
+ // lu = A_0 | A_1 | A_2 = A10 | A11 | A12
459
+ // A20 | A21 | A22
460
+ BlockType A_0(lu,0,0,rows,k);
461
+ BlockType A_2(lu,0,k+bs,rows,tsize);
462
+ BlockType A11(lu,k,k,bs,bs);
463
+ BlockType A12(lu,k,k+bs,bs,tsize);
464
+ BlockType A21(lu,k+bs,k,trows,bs);
465
+ BlockType A22(lu,k+bs,k+bs,trows,tsize);
466
+
467
+ PivIndex nb_transpositions_in_panel;
468
+ // recursively call the blocked LU algorithm on [A11^T A21^T]^T
469
+ // with a very small blocking size:
470
+ Index ret = blocked_lu(trows+bs, bs, &lu.coeffRef(k,k), luStride,
471
+ row_transpositions+k, nb_transpositions_in_panel, 16);
472
+ if(ret>=0 && first_zero_pivot==-1)
473
+ first_zero_pivot = k+ret;
474
+
475
+ nb_transpositions += nb_transpositions_in_panel;
476
+ // update permutations and apply them to A_0
477
+ for(Index i=k; i<k+bs; ++i)
478
+ {
479
+ Index piv = (row_transpositions[i] += internal::convert_index<PivIndex>(k));
480
+ A_0.row(i).swap(A_0.row(piv));
481
+ }
482
+
483
+ if(trows)
484
+ {
485
+ // apply permutations to A_2
486
+ for(Index i=k;i<k+bs; ++i)
487
+ A_2.row(i).swap(A_2.row(row_transpositions[i]));
488
+
489
+ // A12 = A11^-1 A12
490
+ A11.template triangularView<UnitLower>().solveInPlace(A12);
491
+
492
+ A22.noalias() -= A21 * A12;
493
+ }
494
+ }
495
+ return first_zero_pivot;
496
+ }
497
+ };
498
+
499
+ /** \internal performs the LU decomposition with partial pivoting in-place.
500
+ */
501
+ template<typename MatrixType, typename TranspositionType>
502
+ void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, typename TranspositionType::StorageIndex& nb_transpositions)
503
+ {
504
+ eigen_assert(lu.cols() == row_transpositions.size());
505
+ eigen_assert((&row_transpositions.coeffRef(1)-&row_transpositions.coeffRef(0)) == 1);
506
+
507
+ partial_lu_impl
508
+ <typename MatrixType::Scalar, MatrixType::Flags&RowMajorBit?RowMajor:ColMajor, typename TranspositionType::StorageIndex>
509
+ ::blocked_lu(lu.rows(), lu.cols(), &lu.coeffRef(0,0), lu.outerStride(), &row_transpositions.coeffRef(0), nb_transpositions);
510
+ }
511
+
512
+ } // end namespace internal
513
+
514
+ template<typename MatrixType>
515
+ void PartialPivLU<MatrixType>::compute()
516
+ {
517
+ check_template_parameters();
518
+
519
+ // the row permutation is stored as int indices, so just to be sure:
520
+ eigen_assert(m_lu.rows()<NumTraits<int>::highest());
521
+
522
+ m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff();
523
+
524
+ eigen_assert(m_lu.rows() == m_lu.cols() && "PartialPivLU is only for square (and moreover invertible) matrices");
525
+ const Index size = m_lu.rows();
526
+
527
+ m_rowsTranspositions.resize(size);
528
+
529
+ typename TranspositionType::StorageIndex nb_transpositions;
530
+ internal::partial_lu_inplace(m_lu, m_rowsTranspositions, nb_transpositions);
531
+ m_det_p = (nb_transpositions%2) ? -1 : 1;
532
+
533
+ m_p = m_rowsTranspositions;
534
+
535
+ m_isInitialized = true;
536
+ }
537
+
538
+ template<typename MatrixType>
539
+ typename PartialPivLU<MatrixType>::Scalar PartialPivLU<MatrixType>::determinant() const
540
+ {
541
+ eigen_assert(m_isInitialized && "PartialPivLU is not initialized.");
542
+ return Scalar(m_det_p) * m_lu.diagonal().prod();
543
+ }
544
+
545
+ /** \returns the matrix represented by the decomposition,
546
+ * i.e., it returns the product: P^{-1} L U.
547
+ * This function is provided for debug purpose. */
548
+ template<typename MatrixType>
549
+ MatrixType PartialPivLU<MatrixType>::reconstructedMatrix() const
550
+ {
551
+ eigen_assert(m_isInitialized && "LU is not initialized.");
552
+ // LU
553
+ MatrixType res = m_lu.template triangularView<UnitLower>().toDenseMatrix()
554
+ * m_lu.template triangularView<Upper>();
555
+
556
+ // P^{-1}(LU)
557
+ res = m_p.inverse() * res;
558
+
559
+ return res;
560
+ }
561
+
562
+ /***** Implementation details *****************************************************/
563
+
564
+ namespace internal {
565
+
566
+ /***** Implementation of inverse() *****************************************************/
567
+ template<typename DstXprType, typename MatrixType>
568
+ struct Assignment<DstXprType, Inverse<PartialPivLU<MatrixType> >, internal::assign_op<typename DstXprType::Scalar,typename PartialPivLU<MatrixType>::Scalar>, Dense2Dense>
569
+ {
570
+ typedef PartialPivLU<MatrixType> LuType;
571
+ typedef Inverse<LuType> SrcXprType;
572
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<typename DstXprType::Scalar,typename LuType::Scalar> &)
573
+ {
574
+ dst = src.nestedExpression().solve(MatrixType::Identity(src.rows(), src.cols()));
575
+ }
576
+ };
577
+ } // end namespace internal
578
+
579
+ /******** MatrixBase methods *******/
580
+
581
+ /** \lu_module
582
+ *
583
+ * \return the partial-pivoting LU decomposition of \c *this.
584
+ *
585
+ * \sa class PartialPivLU
586
+ */
587
+ template<typename Derived>
588
+ inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject>
589
+ MatrixBase<Derived>::partialPivLu() const
590
+ {
591
+ return PartialPivLU<PlainObject>(eval());
592
+ }
593
+
594
+ /** \lu_module
595
+ *
596
+ * Synonym of partialPivLu().
597
+ *
598
+ * \return the partial-pivoting LU decomposition of \c *this.
599
+ *
600
+ * \sa class PartialPivLU
601
+ */
602
+ template<typename Derived>
603
+ inline const PartialPivLU<typename MatrixBase<Derived>::PlainObject>
604
+ MatrixBase<Derived>::lu() const
605
+ {
606
+ return PartialPivLU<PlainObject>(eval());
607
+ }
608
+
609
+ } // end namespace Eigen
610
+
611
+ #endif // EIGEN_PARTIALLU_H