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,804 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5
+ // Copyright (C) 2013-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_JACOBISVD_H
12
+ #define EIGEN_JACOBISVD_H
13
+
14
+ namespace Eigen {
15
+
16
+ namespace internal {
17
+ // forward declaration (needed by ICC)
18
+ // the empty body is required by MSVC
19
+ template<typename MatrixType, int QRPreconditioner,
20
+ bool IsComplex = NumTraits<typename MatrixType::Scalar>::IsComplex>
21
+ struct svd_precondition_2x2_block_to_be_real {};
22
+
23
+ /*** QR preconditioners (R-SVD)
24
+ ***
25
+ *** Their role is to reduce the problem of computing the SVD to the case of a square matrix.
26
+ *** This approach, known as R-SVD, is an optimization for rectangular-enough matrices, and is a requirement for
27
+ *** JacobiSVD which by itself is only able to work on square matrices.
28
+ ***/
29
+
30
+ enum { PreconditionIfMoreColsThanRows, PreconditionIfMoreRowsThanCols };
31
+
32
+ template<typename MatrixType, int QRPreconditioner, int Case>
33
+ struct qr_preconditioner_should_do_anything
34
+ {
35
+ enum { a = MatrixType::RowsAtCompileTime != Dynamic &&
36
+ MatrixType::ColsAtCompileTime != Dynamic &&
37
+ MatrixType::ColsAtCompileTime <= MatrixType::RowsAtCompileTime,
38
+ b = MatrixType::RowsAtCompileTime != Dynamic &&
39
+ MatrixType::ColsAtCompileTime != Dynamic &&
40
+ MatrixType::RowsAtCompileTime <= MatrixType::ColsAtCompileTime,
41
+ ret = !( (QRPreconditioner == NoQRPreconditioner) ||
42
+ (Case == PreconditionIfMoreColsThanRows && bool(a)) ||
43
+ (Case == PreconditionIfMoreRowsThanCols && bool(b)) )
44
+ };
45
+ };
46
+
47
+ template<typename MatrixType, int QRPreconditioner, int Case,
48
+ bool DoAnything = qr_preconditioner_should_do_anything<MatrixType, QRPreconditioner, Case>::ret
49
+ > struct qr_preconditioner_impl {};
50
+
51
+ template<typename MatrixType, int QRPreconditioner, int Case>
52
+ class qr_preconditioner_impl<MatrixType, QRPreconditioner, Case, false>
53
+ {
54
+ public:
55
+ void allocate(const JacobiSVD<MatrixType, QRPreconditioner>&) {}
56
+ bool run(JacobiSVD<MatrixType, QRPreconditioner>&, const MatrixType&)
57
+ {
58
+ return false;
59
+ }
60
+ };
61
+
62
+ /*** preconditioner using FullPivHouseholderQR ***/
63
+
64
+ template<typename MatrixType>
65
+ class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
66
+ {
67
+ public:
68
+ typedef typename MatrixType::Scalar Scalar;
69
+ enum
70
+ {
71
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
72
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime
73
+ };
74
+ typedef Matrix<Scalar, 1, RowsAtCompileTime, RowMajor, 1, MaxRowsAtCompileTime> WorkspaceType;
75
+
76
+ void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd)
77
+ {
78
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
79
+ {
80
+ m_qr.~QRType();
81
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
82
+ }
83
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
84
+ }
85
+
86
+ bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
87
+ {
88
+ if(matrix.rows() > matrix.cols())
89
+ {
90
+ m_qr.compute(matrix);
91
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
92
+ if(svd.m_computeFullU) m_qr.matrixQ().evalTo(svd.m_matrixU, m_workspace);
93
+ if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation();
94
+ return true;
95
+ }
96
+ return false;
97
+ }
98
+ private:
99
+ typedef FullPivHouseholderQR<MatrixType> QRType;
100
+ QRType m_qr;
101
+ WorkspaceType m_workspace;
102
+ };
103
+
104
+ template<typename MatrixType>
105
+ class qr_preconditioner_impl<MatrixType, FullPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
106
+ {
107
+ public:
108
+ typedef typename MatrixType::Scalar Scalar;
109
+ enum
110
+ {
111
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
112
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
113
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
114
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
115
+ TrOptions = RowsAtCompileTime==1 ? (MatrixType::Options & ~(RowMajor))
116
+ : ColsAtCompileTime==1 ? (MatrixType::Options | RowMajor)
117
+ : MatrixType::Options
118
+ };
119
+ typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, TrOptions, MaxColsAtCompileTime, MaxRowsAtCompileTime>
120
+ TransposeTypeWithSameStorageOrder;
121
+
122
+ void allocate(const JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd)
123
+ {
124
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
125
+ {
126
+ m_qr.~QRType();
127
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
128
+ }
129
+ m_adjoint.resize(svd.cols(), svd.rows());
130
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
131
+ }
132
+
133
+ bool run(JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
134
+ {
135
+ if(matrix.cols() > matrix.rows())
136
+ {
137
+ m_adjoint = matrix.adjoint();
138
+ m_qr.compute(m_adjoint);
139
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
140
+ if(svd.m_computeFullV) m_qr.matrixQ().evalTo(svd.m_matrixV, m_workspace);
141
+ if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation();
142
+ return true;
143
+ }
144
+ else return false;
145
+ }
146
+ private:
147
+ typedef FullPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
148
+ QRType m_qr;
149
+ TransposeTypeWithSameStorageOrder m_adjoint;
150
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
151
+ };
152
+
153
+ /*** preconditioner using ColPivHouseholderQR ***/
154
+
155
+ template<typename MatrixType>
156
+ class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
157
+ {
158
+ public:
159
+ void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd)
160
+ {
161
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
162
+ {
163
+ m_qr.~QRType();
164
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
165
+ }
166
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
167
+ else if (svd.m_computeThinU) m_workspace.resize(svd.cols());
168
+ }
169
+
170
+ bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
171
+ {
172
+ if(matrix.rows() > matrix.cols())
173
+ {
174
+ m_qr.compute(matrix);
175
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
176
+ if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace);
177
+ else if(svd.m_computeThinU)
178
+ {
179
+ svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols());
180
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace);
181
+ }
182
+ if(svd.computeV()) svd.m_matrixV = m_qr.colsPermutation();
183
+ return true;
184
+ }
185
+ return false;
186
+ }
187
+
188
+ private:
189
+ typedef ColPivHouseholderQR<MatrixType> QRType;
190
+ QRType m_qr;
191
+ typename internal::plain_col_type<MatrixType>::type m_workspace;
192
+ };
193
+
194
+ template<typename MatrixType>
195
+ class qr_preconditioner_impl<MatrixType, ColPivHouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
196
+ {
197
+ public:
198
+ typedef typename MatrixType::Scalar Scalar;
199
+ enum
200
+ {
201
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
202
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
203
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
204
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
205
+ TrOptions = RowsAtCompileTime==1 ? (MatrixType::Options & ~(RowMajor))
206
+ : ColsAtCompileTime==1 ? (MatrixType::Options | RowMajor)
207
+ : MatrixType::Options
208
+ };
209
+
210
+ typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, TrOptions, MaxColsAtCompileTime, MaxRowsAtCompileTime>
211
+ TransposeTypeWithSameStorageOrder;
212
+
213
+ void allocate(const JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd)
214
+ {
215
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
216
+ {
217
+ m_qr.~QRType();
218
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
219
+ }
220
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
221
+ else if (svd.m_computeThinV) m_workspace.resize(svd.rows());
222
+ m_adjoint.resize(svd.cols(), svd.rows());
223
+ }
224
+
225
+ bool run(JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>& svd, const MatrixType& matrix)
226
+ {
227
+ if(matrix.cols() > matrix.rows())
228
+ {
229
+ m_adjoint = matrix.adjoint();
230
+ m_qr.compute(m_adjoint);
231
+
232
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
233
+ if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace);
234
+ else if(svd.m_computeThinV)
235
+ {
236
+ svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows());
237
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace);
238
+ }
239
+ if(svd.computeU()) svd.m_matrixU = m_qr.colsPermutation();
240
+ return true;
241
+ }
242
+ else return false;
243
+ }
244
+
245
+ private:
246
+ typedef ColPivHouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
247
+ QRType m_qr;
248
+ TransposeTypeWithSameStorageOrder m_adjoint;
249
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
250
+ };
251
+
252
+ /*** preconditioner using HouseholderQR ***/
253
+
254
+ template<typename MatrixType>
255
+ class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreRowsThanCols, true>
256
+ {
257
+ public:
258
+ void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd)
259
+ {
260
+ if (svd.rows() != m_qr.rows() || svd.cols() != m_qr.cols())
261
+ {
262
+ m_qr.~QRType();
263
+ ::new (&m_qr) QRType(svd.rows(), svd.cols());
264
+ }
265
+ if (svd.m_computeFullU) m_workspace.resize(svd.rows());
266
+ else if (svd.m_computeThinU) m_workspace.resize(svd.cols());
267
+ }
268
+
269
+ bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix)
270
+ {
271
+ if(matrix.rows() > matrix.cols())
272
+ {
273
+ m_qr.compute(matrix);
274
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.cols(),matrix.cols()).template triangularView<Upper>();
275
+ if(svd.m_computeFullU) m_qr.householderQ().evalTo(svd.m_matrixU, m_workspace);
276
+ else if(svd.m_computeThinU)
277
+ {
278
+ svd.m_matrixU.setIdentity(matrix.rows(), matrix.cols());
279
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixU, m_workspace);
280
+ }
281
+ if(svd.computeV()) svd.m_matrixV.setIdentity(matrix.cols(), matrix.cols());
282
+ return true;
283
+ }
284
+ return false;
285
+ }
286
+ private:
287
+ typedef HouseholderQR<MatrixType> QRType;
288
+ QRType m_qr;
289
+ typename internal::plain_col_type<MatrixType>::type m_workspace;
290
+ };
291
+
292
+ template<typename MatrixType>
293
+ class qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, PreconditionIfMoreColsThanRows, true>
294
+ {
295
+ public:
296
+ typedef typename MatrixType::Scalar Scalar;
297
+ enum
298
+ {
299
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
300
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
301
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
302
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
303
+ Options = MatrixType::Options
304
+ };
305
+
306
+ typedef Matrix<Scalar, ColsAtCompileTime, RowsAtCompileTime, Options, MaxColsAtCompileTime, MaxRowsAtCompileTime>
307
+ TransposeTypeWithSameStorageOrder;
308
+
309
+ void allocate(const JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd)
310
+ {
311
+ if (svd.cols() != m_qr.rows() || svd.rows() != m_qr.cols())
312
+ {
313
+ m_qr.~QRType();
314
+ ::new (&m_qr) QRType(svd.cols(), svd.rows());
315
+ }
316
+ if (svd.m_computeFullV) m_workspace.resize(svd.cols());
317
+ else if (svd.m_computeThinV) m_workspace.resize(svd.rows());
318
+ m_adjoint.resize(svd.cols(), svd.rows());
319
+ }
320
+
321
+ bool run(JacobiSVD<MatrixType, HouseholderQRPreconditioner>& svd, const MatrixType& matrix)
322
+ {
323
+ if(matrix.cols() > matrix.rows())
324
+ {
325
+ m_adjoint = matrix.adjoint();
326
+ m_qr.compute(m_adjoint);
327
+
328
+ svd.m_workMatrix = m_qr.matrixQR().block(0,0,matrix.rows(),matrix.rows()).template triangularView<Upper>().adjoint();
329
+ if(svd.m_computeFullV) m_qr.householderQ().evalTo(svd.m_matrixV, m_workspace);
330
+ else if(svd.m_computeThinV)
331
+ {
332
+ svd.m_matrixV.setIdentity(matrix.cols(), matrix.rows());
333
+ m_qr.householderQ().applyThisOnTheLeft(svd.m_matrixV, m_workspace);
334
+ }
335
+ if(svd.computeU()) svd.m_matrixU.setIdentity(matrix.rows(), matrix.rows());
336
+ return true;
337
+ }
338
+ else return false;
339
+ }
340
+
341
+ private:
342
+ typedef HouseholderQR<TransposeTypeWithSameStorageOrder> QRType;
343
+ QRType m_qr;
344
+ TransposeTypeWithSameStorageOrder m_adjoint;
345
+ typename internal::plain_row_type<MatrixType>::type m_workspace;
346
+ };
347
+
348
+ /*** 2x2 SVD implementation
349
+ ***
350
+ *** JacobiSVD consists in performing a series of 2x2 SVD subproblems
351
+ ***/
352
+
353
+ template<typename MatrixType, int QRPreconditioner>
354
+ struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, false>
355
+ {
356
+ typedef JacobiSVD<MatrixType, QRPreconditioner> SVD;
357
+ typedef typename MatrixType::RealScalar RealScalar;
358
+ static bool run(typename SVD::WorkMatrixType&, SVD&, Index, Index, RealScalar&) { return true; }
359
+ };
360
+
361
+ template<typename MatrixType, int QRPreconditioner>
362
+ struct svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner, true>
363
+ {
364
+ typedef JacobiSVD<MatrixType, QRPreconditioner> SVD;
365
+ typedef typename MatrixType::Scalar Scalar;
366
+ typedef typename MatrixType::RealScalar RealScalar;
367
+ static bool run(typename SVD::WorkMatrixType& work_matrix, SVD& svd, Index p, Index q, RealScalar& maxDiagEntry)
368
+ {
369
+ using std::sqrt;
370
+ using std::abs;
371
+ Scalar z;
372
+ JacobiRotation<Scalar> rot;
373
+ RealScalar n = sqrt(numext::abs2(work_matrix.coeff(p,p)) + numext::abs2(work_matrix.coeff(q,p)));
374
+
375
+ const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
376
+ const RealScalar precision = NumTraits<Scalar>::epsilon();
377
+
378
+ if(n==0)
379
+ {
380
+ // make sure first column is zero
381
+ work_matrix.coeffRef(p,p) = work_matrix.coeffRef(q,p) = Scalar(0);
382
+
383
+ if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero)
384
+ {
385
+ // 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
386
+ z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q);
387
+ work_matrix.row(p) *= z;
388
+ if(svd.computeU()) svd.m_matrixU.col(p) *= conj(z);
389
+ }
390
+ if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero)
391
+ {
392
+ z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q);
393
+ work_matrix.row(q) *= z;
394
+ if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z);
395
+ }
396
+ // otherwise the second row is already zero, so we have nothing to do.
397
+ }
398
+ else
399
+ {
400
+ rot.c() = conj(work_matrix.coeff(p,p)) / n;
401
+ rot.s() = work_matrix.coeff(q,p) / n;
402
+ work_matrix.applyOnTheLeft(p,q,rot);
403
+ if(svd.computeU()) svd.m_matrixU.applyOnTheRight(p,q,rot.adjoint());
404
+ if(abs(numext::imag(work_matrix.coeff(p,q)))>considerAsZero)
405
+ {
406
+ z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q);
407
+ work_matrix.col(q) *= z;
408
+ if(svd.computeV()) svd.m_matrixV.col(q) *= z;
409
+ }
410
+ if(abs(numext::imag(work_matrix.coeff(q,q)))>considerAsZero)
411
+ {
412
+ z = abs(work_matrix.coeff(q,q)) / work_matrix.coeff(q,q);
413
+ work_matrix.row(q) *= z;
414
+ if(svd.computeU()) svd.m_matrixU.col(q) *= conj(z);
415
+ }
416
+ }
417
+
418
+ // update largest diagonal entry
419
+ maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(work_matrix.coeff(p,p)), abs(work_matrix.coeff(q,q))));
420
+ // and check whether the 2x2 block is already diagonal
421
+ RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry);
422
+ return abs(work_matrix.coeff(p,q))>threshold || abs(work_matrix.coeff(q,p)) > threshold;
423
+ }
424
+ };
425
+
426
+ template<typename _MatrixType, int QRPreconditioner>
427
+ struct traits<JacobiSVD<_MatrixType,QRPreconditioner> >
428
+ {
429
+ typedef _MatrixType MatrixType;
430
+ };
431
+
432
+ } // end namespace internal
433
+
434
+ /** \ingroup SVD_Module
435
+ *
436
+ *
437
+ * \class JacobiSVD
438
+ *
439
+ * \brief Two-sided Jacobi SVD decomposition of a rectangular matrix
440
+ *
441
+ * \tparam _MatrixType the type of the matrix of which we are computing the SVD decomposition
442
+ * \tparam QRPreconditioner this optional parameter allows to specify the type of QR decomposition that will be used internally
443
+ * for the R-SVD step for non-square matrices. See discussion of possible values below.
444
+ *
445
+ * SVD decomposition consists in decomposing any n-by-p matrix \a A as a product
446
+ * \f[ A = U S V^* \f]
447
+ * 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;
448
+ * 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
449
+ * and right \em singular \em vectors of \a A respectively.
450
+ *
451
+ * Singular values are always sorted in decreasing order.
452
+ *
453
+ * 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.
454
+ *
455
+ * 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
456
+ * 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
457
+ * 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,
458
+ * 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.
459
+ *
460
+ * Here's an example demonstrating basic usage:
461
+ * \include JacobiSVD_basic.cpp
462
+ * Output: \verbinclude JacobiSVD_basic.out
463
+ *
464
+ * This JacobiSVD class is a two-sided Jacobi R-SVD decomposition, ensuring optimal reliability and accuracy. The downside is that it's slower than
465
+ * 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
466
+ * \a p is the greater dimension, meaning that it is still of the same order of complexity as the faster bidiagonalizing R-SVD algorithms.
467
+ * In particular, like any R-SVD, it takes advantage of non-squareness in that its complexity is only linear in the greater dimension.
468
+ *
469
+ * If the input matrix has inf or nan coefficients, the result of the computation is undefined, but the computation is guaranteed to
470
+ * terminate in finite (and reasonable) time.
471
+ *
472
+ * The possible values for QRPreconditioner are:
473
+ * \li ColPivHouseholderQRPreconditioner is the default. In practice it's very safe. It uses column-pivoting QR.
474
+ * \li FullPivHouseholderQRPreconditioner, is the safest and slowest. It uses full-pivoting QR.
475
+ * Contrary to other QRs, it doesn't allow computing thin unitaries.
476
+ * \li HouseholderQRPreconditioner is the fastest, and less safe and accurate than the pivoting variants. It uses non-pivoting QR.
477
+ * This is very similar in safety and accuracy to the bidiagonalization process used by bidiagonalizing SVD algorithms (since bidiagonalization
478
+ * is inherently non-pivoting). However the resulting SVD is still more reliable than bidiagonalizing SVDs because the Jacobi-based iterarive
479
+ * process is more reliable than the optimized bidiagonal SVD iterations.
480
+ * \li NoQRPreconditioner allows not to use a QR preconditioner at all. This is useful if you know that you will only be computing
481
+ * JacobiSVD decompositions of square matrices. Non-square matrices require a QR preconditioner. Using this option will result in
482
+ * faster compilation and smaller executable code. It won't significantly speed up computation, since JacobiSVD is always checking
483
+ * if QR preconditioning is needed before applying it anyway.
484
+ *
485
+ * \sa MatrixBase::jacobiSvd()
486
+ */
487
+ template<typename _MatrixType, int QRPreconditioner> class JacobiSVD
488
+ : public SVDBase<JacobiSVD<_MatrixType,QRPreconditioner> >
489
+ {
490
+ typedef SVDBase<JacobiSVD> Base;
491
+ public:
492
+
493
+ typedef _MatrixType MatrixType;
494
+ typedef typename MatrixType::Scalar Scalar;
495
+ typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
496
+ enum {
497
+ RowsAtCompileTime = MatrixType::RowsAtCompileTime,
498
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
499
+ DiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_DYNAMIC(RowsAtCompileTime,ColsAtCompileTime),
500
+ MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
501
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
502
+ MaxDiagSizeAtCompileTime = EIGEN_SIZE_MIN_PREFER_FIXED(MaxRowsAtCompileTime,MaxColsAtCompileTime),
503
+ MatrixOptions = MatrixType::Options
504
+ };
505
+
506
+ typedef typename Base::MatrixUType MatrixUType;
507
+ typedef typename Base::MatrixVType MatrixVType;
508
+ typedef typename Base::SingularValuesType SingularValuesType;
509
+
510
+ typedef typename internal::plain_row_type<MatrixType>::type RowType;
511
+ typedef typename internal::plain_col_type<MatrixType>::type ColType;
512
+ typedef Matrix<Scalar, DiagSizeAtCompileTime, DiagSizeAtCompileTime,
513
+ MatrixOptions, MaxDiagSizeAtCompileTime, MaxDiagSizeAtCompileTime>
514
+ WorkMatrixType;
515
+
516
+ /** \brief Default Constructor.
517
+ *
518
+ * The default constructor is useful in cases in which the user intends to
519
+ * perform decompositions via JacobiSVD::compute(const MatrixType&).
520
+ */
521
+ JacobiSVD()
522
+ {}
523
+
524
+
525
+ /** \brief Default Constructor with memory preallocation
526
+ *
527
+ * Like the default constructor but with preallocation of the internal data
528
+ * according to the specified problem size.
529
+ * \sa JacobiSVD()
530
+ */
531
+ JacobiSVD(Index rows, Index cols, unsigned int computationOptions = 0)
532
+ {
533
+ allocate(rows, cols, computationOptions);
534
+ }
535
+
536
+ /** \brief Constructor performing the decomposition of given matrix.
537
+ *
538
+ * \param matrix the matrix to decompose
539
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
540
+ * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU,
541
+ * #ComputeFullV, #ComputeThinV.
542
+ *
543
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
544
+ * available with the (non-default) FullPivHouseholderQR preconditioner.
545
+ */
546
+ explicit JacobiSVD(const MatrixType& matrix, unsigned int computationOptions = 0)
547
+ {
548
+ compute(matrix, computationOptions);
549
+ }
550
+
551
+ /** \brief Method performing the decomposition of given matrix using custom options.
552
+ *
553
+ * \param matrix the matrix to decompose
554
+ * \param computationOptions optional parameter allowing to specify if you want full or thin U or V unitaries to be computed.
555
+ * By default, none is computed. This is a bit-field, the possible bits are #ComputeFullU, #ComputeThinU,
556
+ * #ComputeFullV, #ComputeThinV.
557
+ *
558
+ * Thin unitaries are only available if your matrix type has a Dynamic number of columns (for example MatrixXf). They also are not
559
+ * available with the (non-default) FullPivHouseholderQR preconditioner.
560
+ */
561
+ JacobiSVD& compute(const MatrixType& matrix, unsigned int computationOptions);
562
+
563
+ /** \brief Method performing the decomposition of given matrix using current options.
564
+ *
565
+ * \param matrix the matrix to decompose
566
+ *
567
+ * This method uses the current \a computationOptions, as already passed to the constructor or to compute(const MatrixType&, unsigned int).
568
+ */
569
+ JacobiSVD& compute(const MatrixType& matrix)
570
+ {
571
+ return compute(matrix, m_computationOptions);
572
+ }
573
+
574
+ using Base::computeU;
575
+ using Base::computeV;
576
+ using Base::rows;
577
+ using Base::cols;
578
+ using Base::rank;
579
+
580
+ private:
581
+ void allocate(Index rows, Index cols, unsigned int computationOptions);
582
+
583
+ protected:
584
+ using Base::m_matrixU;
585
+ using Base::m_matrixV;
586
+ using Base::m_singularValues;
587
+ using Base::m_isInitialized;
588
+ using Base::m_isAllocated;
589
+ using Base::m_usePrescribedThreshold;
590
+ using Base::m_computeFullU;
591
+ using Base::m_computeThinU;
592
+ using Base::m_computeFullV;
593
+ using Base::m_computeThinV;
594
+ using Base::m_computationOptions;
595
+ using Base::m_nonzeroSingularValues;
596
+ using Base::m_rows;
597
+ using Base::m_cols;
598
+ using Base::m_diagSize;
599
+ using Base::m_prescribedThreshold;
600
+ WorkMatrixType m_workMatrix;
601
+
602
+ template<typename __MatrixType, int _QRPreconditioner, bool _IsComplex>
603
+ friend struct internal::svd_precondition_2x2_block_to_be_real;
604
+ template<typename __MatrixType, int _QRPreconditioner, int _Case, bool _DoAnything>
605
+ friend struct internal::qr_preconditioner_impl;
606
+
607
+ internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreColsThanRows> m_qr_precond_morecols;
608
+ internal::qr_preconditioner_impl<MatrixType, QRPreconditioner, internal::PreconditionIfMoreRowsThanCols> m_qr_precond_morerows;
609
+ MatrixType m_scaledMatrix;
610
+ };
611
+
612
+ template<typename MatrixType, int QRPreconditioner>
613
+ void JacobiSVD<MatrixType, QRPreconditioner>::allocate(Index rows, Index cols, unsigned int computationOptions)
614
+ {
615
+ eigen_assert(rows >= 0 && cols >= 0);
616
+
617
+ if (m_isAllocated &&
618
+ rows == m_rows &&
619
+ cols == m_cols &&
620
+ computationOptions == m_computationOptions)
621
+ {
622
+ return;
623
+ }
624
+
625
+ m_rows = rows;
626
+ m_cols = cols;
627
+ m_isInitialized = false;
628
+ m_isAllocated = true;
629
+ m_computationOptions = computationOptions;
630
+ m_computeFullU = (computationOptions & ComputeFullU) != 0;
631
+ m_computeThinU = (computationOptions & ComputeThinU) != 0;
632
+ m_computeFullV = (computationOptions & ComputeFullV) != 0;
633
+ m_computeThinV = (computationOptions & ComputeThinV) != 0;
634
+ eigen_assert(!(m_computeFullU && m_computeThinU) && "JacobiSVD: you can't ask for both full and thin U");
635
+ eigen_assert(!(m_computeFullV && m_computeThinV) && "JacobiSVD: you can't ask for both full and thin V");
636
+ eigen_assert(EIGEN_IMPLIES(m_computeThinU || m_computeThinV, MatrixType::ColsAtCompileTime==Dynamic) &&
637
+ "JacobiSVD: thin U and V are only available when your matrix has a dynamic number of columns.");
638
+ if (QRPreconditioner == FullPivHouseholderQRPreconditioner)
639
+ {
640
+ eigen_assert(!(m_computeThinU || m_computeThinV) &&
641
+ "JacobiSVD: can't compute thin U or thin V with the FullPivHouseholderQR preconditioner. "
642
+ "Use the ColPivHouseholderQR preconditioner instead.");
643
+ }
644
+ m_diagSize = (std::min)(m_rows, m_cols);
645
+ m_singularValues.resize(m_diagSize);
646
+ if(RowsAtCompileTime==Dynamic)
647
+ m_matrixU.resize(m_rows, m_computeFullU ? m_rows
648
+ : m_computeThinU ? m_diagSize
649
+ : 0);
650
+ if(ColsAtCompileTime==Dynamic)
651
+ m_matrixV.resize(m_cols, m_computeFullV ? m_cols
652
+ : m_computeThinV ? m_diagSize
653
+ : 0);
654
+ m_workMatrix.resize(m_diagSize, m_diagSize);
655
+
656
+ if(m_cols>m_rows) m_qr_precond_morecols.allocate(*this);
657
+ if(m_rows>m_cols) m_qr_precond_morerows.allocate(*this);
658
+ if(m_rows!=m_cols) m_scaledMatrix.resize(rows,cols);
659
+ }
660
+
661
+ template<typename MatrixType, int QRPreconditioner>
662
+ JacobiSVD<MatrixType, QRPreconditioner>&
663
+ JacobiSVD<MatrixType, QRPreconditioner>::compute(const MatrixType& matrix, unsigned int computationOptions)
664
+ {
665
+ using std::abs;
666
+ allocate(matrix.rows(), matrix.cols(), computationOptions);
667
+
668
+ // currently we stop when we reach precision 2*epsilon as the last bit of precision can require an unreasonable number of iterations,
669
+ // only worsening the precision of U and V as we accumulate more rotations
670
+ const RealScalar precision = RealScalar(2) * NumTraits<Scalar>::epsilon();
671
+
672
+ // limit for denormal numbers to be considered zero in order to avoid infinite loops (see bug 286)
673
+ const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
674
+
675
+ // Scaling factor to reduce over/under-flows
676
+ RealScalar scale = matrix.cwiseAbs().maxCoeff();
677
+ if(scale==RealScalar(0)) scale = RealScalar(1);
678
+
679
+ /*** step 1. The R-SVD step: we use a QR decomposition to reduce to the case of a square matrix */
680
+
681
+ if(m_rows!=m_cols)
682
+ {
683
+ m_scaledMatrix = matrix / scale;
684
+ m_qr_precond_morecols.run(*this, m_scaledMatrix);
685
+ m_qr_precond_morerows.run(*this, m_scaledMatrix);
686
+ }
687
+ else
688
+ {
689
+ m_workMatrix = matrix.block(0,0,m_diagSize,m_diagSize) / scale;
690
+ if(m_computeFullU) m_matrixU.setIdentity(m_rows,m_rows);
691
+ if(m_computeThinU) m_matrixU.setIdentity(m_rows,m_diagSize);
692
+ if(m_computeFullV) m_matrixV.setIdentity(m_cols,m_cols);
693
+ if(m_computeThinV) m_matrixV.setIdentity(m_cols, m_diagSize);
694
+ }
695
+
696
+ /*** step 2. The main Jacobi SVD iteration. ***/
697
+ RealScalar maxDiagEntry = m_workMatrix.cwiseAbs().diagonal().maxCoeff();
698
+
699
+ bool finished = false;
700
+ while(!finished)
701
+ {
702
+ finished = true;
703
+
704
+ // do a sweep: for all index pairs (p,q), perform SVD of the corresponding 2x2 sub-matrix
705
+
706
+ for(Index p = 1; p < m_diagSize; ++p)
707
+ {
708
+ for(Index q = 0; q < p; ++q)
709
+ {
710
+ // if this 2x2 sub-matrix is not diagonal already...
711
+ // notice that this comparison will evaluate to false if any NaN is involved, ensuring that NaN's don't
712
+ // keep us iterating forever. Similarly, small denormal numbers are considered zero.
713
+ RealScalar threshold = numext::maxi<RealScalar>(considerAsZero, precision * maxDiagEntry);
714
+ if(abs(m_workMatrix.coeff(p,q))>threshold || abs(m_workMatrix.coeff(q,p)) > threshold)
715
+ {
716
+ finished = false;
717
+ // perform SVD decomposition of 2x2 sub-matrix corresponding to indices p,q to make it diagonal
718
+ // the complex to real operation returns true if the updated 2x2 block is not already diagonal
719
+ if(internal::svd_precondition_2x2_block_to_be_real<MatrixType, QRPreconditioner>::run(m_workMatrix, *this, p, q, maxDiagEntry))
720
+ {
721
+ JacobiRotation<RealScalar> j_left, j_right;
722
+ internal::real_2x2_jacobi_svd(m_workMatrix, p, q, &j_left, &j_right);
723
+
724
+ // accumulate resulting Jacobi rotations
725
+ m_workMatrix.applyOnTheLeft(p,q,j_left);
726
+ if(computeU()) m_matrixU.applyOnTheRight(p,q,j_left.transpose());
727
+
728
+ m_workMatrix.applyOnTheRight(p,q,j_right);
729
+ if(computeV()) m_matrixV.applyOnTheRight(p,q,j_right);
730
+
731
+ // keep track of the largest diagonal coefficient
732
+ maxDiagEntry = numext::maxi<RealScalar>(maxDiagEntry,numext::maxi<RealScalar>(abs(m_workMatrix.coeff(p,p)), abs(m_workMatrix.coeff(q,q))));
733
+ }
734
+ }
735
+ }
736
+ }
737
+ }
738
+
739
+ /*** step 3. The work matrix is now diagonal, so ensure it's positive so its diagonal entries are the singular values ***/
740
+
741
+ for(Index i = 0; i < m_diagSize; ++i)
742
+ {
743
+ // For a complex matrix, some diagonal coefficients might note have been
744
+ // treated by svd_precondition_2x2_block_to_be_real, and the imaginary part
745
+ // of some diagonal entry might not be null.
746
+ if(NumTraits<Scalar>::IsComplex && abs(numext::imag(m_workMatrix.coeff(i,i)))>considerAsZero)
747
+ {
748
+ RealScalar a = abs(m_workMatrix.coeff(i,i));
749
+ m_singularValues.coeffRef(i) = abs(a);
750
+ if(computeU()) m_matrixU.col(i) *= m_workMatrix.coeff(i,i)/a;
751
+ }
752
+ else
753
+ {
754
+ // m_workMatrix.coeff(i,i) is already real, no difficulty:
755
+ RealScalar a = numext::real(m_workMatrix.coeff(i,i));
756
+ m_singularValues.coeffRef(i) = abs(a);
757
+ if(computeU() && (a<RealScalar(0))) m_matrixU.col(i) = -m_matrixU.col(i);
758
+ }
759
+ }
760
+
761
+ m_singularValues *= scale;
762
+
763
+ /*** step 4. Sort singular values in descending order and compute the number of nonzero singular values ***/
764
+
765
+ m_nonzeroSingularValues = m_diagSize;
766
+ for(Index i = 0; i < m_diagSize; i++)
767
+ {
768
+ Index pos;
769
+ RealScalar maxRemainingSingularValue = m_singularValues.tail(m_diagSize-i).maxCoeff(&pos);
770
+ if(maxRemainingSingularValue == RealScalar(0))
771
+ {
772
+ m_nonzeroSingularValues = i;
773
+ break;
774
+ }
775
+ if(pos)
776
+ {
777
+ pos += i;
778
+ std::swap(m_singularValues.coeffRef(i), m_singularValues.coeffRef(pos));
779
+ if(computeU()) m_matrixU.col(pos).swap(m_matrixU.col(i));
780
+ if(computeV()) m_matrixV.col(pos).swap(m_matrixV.col(i));
781
+ }
782
+ }
783
+
784
+ m_isInitialized = true;
785
+ return *this;
786
+ }
787
+
788
+ /** \svd_module
789
+ *
790
+ * \return the singular value decomposition of \c *this computed by two-sided
791
+ * Jacobi transformations.
792
+ *
793
+ * \sa class JacobiSVD
794
+ */
795
+ template<typename Derived>
796
+ JacobiSVD<typename MatrixBase<Derived>::PlainObject>
797
+ MatrixBase<Derived>::jacobiSvd(unsigned int computationOptions) const
798
+ {
799
+ return JacobiSVD<PlainObject>(*this, computationOptions);
800
+ }
801
+
802
+ } // end namespace Eigen
803
+
804
+ #endif // EIGEN_JACOBISVD_H