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,137 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla
7
+ // Public License v. 2.0. If a copy of the MPL was not distributed
8
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
10
+ /*
11
+
12
+ * NOTE: This file is the modified version of xpivotL.c file in SuperLU
13
+
14
+ * -- SuperLU routine (version 3.0) --
15
+ * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16
+ * and Lawrence Berkeley National Lab.
17
+ * October 15, 2003
18
+ *
19
+ * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
20
+ *
21
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
22
+ * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
23
+ *
24
+ * Permission is hereby granted to use or copy this program for any
25
+ * purpose, provided the above notices are retained on all copies.
26
+ * Permission to modify the code and to distribute modified code is
27
+ * granted, provided the above notices are retained, and a notice that
28
+ * the code was modified is included with the above copyright notice.
29
+ */
30
+ #ifndef SPARSELU_PIVOTL_H
31
+ #define SPARSELU_PIVOTL_H
32
+
33
+ namespace Eigen {
34
+ namespace internal {
35
+
36
+ /**
37
+ * \brief Performs the numerical pivotin on the current column of L, and the CDIV operation.
38
+ *
39
+ * Pivot policy :
40
+ * (1) Compute thresh = u * max_(i>=j) abs(A_ij);
41
+ * (2) IF user specifies pivot row k and abs(A_kj) >= thresh THEN
42
+ * pivot row = k;
43
+ * ELSE IF abs(A_jj) >= thresh THEN
44
+ * pivot row = j;
45
+ * ELSE
46
+ * pivot row = m;
47
+ *
48
+ * Note: If you absolutely want to use a given pivot order, then set u=0.0.
49
+ *
50
+ * \param jcol The current column of L
51
+ * \param diagpivotthresh diagonal pivoting threshold
52
+ * \param[in,out] perm_r Row permutation (threshold pivoting)
53
+ * \param[in] iperm_c column permutation - used to finf diagonal of Pc*A*Pc'
54
+ * \param[out] pivrow The pivot row
55
+ * \param glu Global LU data
56
+ * \return 0 if success, i > 0 if U(i,i) is exactly zero
57
+ *
58
+ */
59
+ template <typename Scalar, typename StorageIndex>
60
+ Index SparseLUImpl<Scalar,StorageIndex>::pivotL(const Index jcol, const RealScalar& diagpivotthresh, IndexVector& perm_r, IndexVector& iperm_c, Index& pivrow, GlobalLU_t& glu)
61
+ {
62
+
63
+ Index fsupc = (glu.xsup)((glu.supno)(jcol)); // First column in the supernode containing the column jcol
64
+ Index nsupc = jcol - fsupc; // Number of columns in the supernode portion, excluding jcol; nsupc >=0
65
+ Index lptr = glu.xlsub(fsupc); // pointer to the starting location of the row subscripts for this supernode portion
66
+ Index nsupr = glu.xlsub(fsupc+1) - lptr; // Number of rows in the supernode
67
+ Index lda = glu.xlusup(fsupc+1) - glu.xlusup(fsupc); // leading dimension
68
+ Scalar* lu_sup_ptr = &(glu.lusup.data()[glu.xlusup(fsupc)]); // Start of the current supernode
69
+ Scalar* lu_col_ptr = &(glu.lusup.data()[glu.xlusup(jcol)]); // Start of jcol in the supernode
70
+ StorageIndex* lsub_ptr = &(glu.lsub.data()[lptr]); // Start of row indices of the supernode
71
+
72
+ // Determine the largest abs numerical value for partial pivoting
73
+ Index diagind = iperm_c(jcol); // diagonal index
74
+ RealScalar pivmax(-1.0);
75
+ Index pivptr = nsupc;
76
+ Index diag = emptyIdxLU;
77
+ RealScalar rtemp;
78
+ Index isub, icol, itemp, k;
79
+ for (isub = nsupc; isub < nsupr; ++isub) {
80
+ using std::abs;
81
+ rtemp = abs(lu_col_ptr[isub]);
82
+ if (rtemp > pivmax) {
83
+ pivmax = rtemp;
84
+ pivptr = isub;
85
+ }
86
+ if (lsub_ptr[isub] == diagind) diag = isub;
87
+ }
88
+
89
+ // Test for singularity
90
+ if ( pivmax <= RealScalar(0.0) ) {
91
+ // if pivmax == -1, the column is structurally empty, otherwise it is only numerically zero
92
+ pivrow = pivmax < RealScalar(0.0) ? diagind : lsub_ptr[pivptr];
93
+ perm_r(pivrow) = StorageIndex(jcol);
94
+ return (jcol+1);
95
+ }
96
+
97
+ RealScalar thresh = diagpivotthresh * pivmax;
98
+
99
+ // Choose appropriate pivotal element
100
+
101
+ {
102
+ // Test if the diagonal element can be used as a pivot (given the threshold value)
103
+ if (diag >= 0 )
104
+ {
105
+ // Diagonal element exists
106
+ using std::abs;
107
+ rtemp = abs(lu_col_ptr[diag]);
108
+ if (rtemp != RealScalar(0.0) && rtemp >= thresh) pivptr = diag;
109
+ }
110
+ pivrow = lsub_ptr[pivptr];
111
+ }
112
+
113
+ // Record pivot row
114
+ perm_r(pivrow) = StorageIndex(jcol);
115
+ // Interchange row subscripts
116
+ if (pivptr != nsupc )
117
+ {
118
+ std::swap( lsub_ptr[pivptr], lsub_ptr[nsupc] );
119
+ // Interchange numerical values as well, for the two rows in the whole snode
120
+ // such that L is indexed the same way as A
121
+ for (icol = 0; icol <= nsupc; icol++)
122
+ {
123
+ itemp = pivptr + icol * lda;
124
+ std::swap(lu_sup_ptr[itemp], lu_sup_ptr[nsupc + icol * lda]);
125
+ }
126
+ }
127
+ // cdiv operations
128
+ Scalar temp = Scalar(1.0) / lu_col_ptr[nsupc];
129
+ for (k = nsupc+1; k < nsupr; k++)
130
+ lu_col_ptr[k] *= temp;
131
+ return 0;
132
+ }
133
+
134
+ } // end namespace internal
135
+ } // end namespace Eigen
136
+
137
+ #endif // SPARSELU_PIVOTL_H
@@ -0,0 +1,136 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla
7
+ // Public License v. 2.0. If a copy of the MPL was not distributed
8
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
10
+ /*
11
+
12
+ * NOTE: This file is the modified version of [s,d,c,z]pruneL.c file in SuperLU
13
+
14
+ * -- SuperLU routine (version 2.0) --
15
+ * Univ. of California Berkeley, Xerox Palo Alto Research Center,
16
+ * and Lawrence Berkeley National Lab.
17
+ * November 15, 1997
18
+ *
19
+ * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
20
+ *
21
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
22
+ * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
23
+ *
24
+ * Permission is hereby granted to use or copy this program for any
25
+ * purpose, provided the above notices are retained on all copies.
26
+ * Permission to modify the code and to distribute modified code is
27
+ * granted, provided the above notices are retained, and a notice that
28
+ * the code was modified is included with the above copyright notice.
29
+ */
30
+ #ifndef SPARSELU_PRUNEL_H
31
+ #define SPARSELU_PRUNEL_H
32
+
33
+ namespace Eigen {
34
+ namespace internal {
35
+
36
+ /**
37
+ * \brief Prunes the L-structure.
38
+ *
39
+ * It prunes the L-structure of supernodes whose L-structure contains the current pivot row "pivrow"
40
+ *
41
+ *
42
+ * \param jcol The current column of L
43
+ * \param[in] perm_r Row permutation
44
+ * \param[out] pivrow The pivot row
45
+ * \param nseg Number of segments
46
+ * \param segrep
47
+ * \param repfnz
48
+ * \param[out] xprune
49
+ * \param glu Global LU data
50
+ *
51
+ */
52
+ template <typename Scalar, typename StorageIndex>
53
+ void SparseLUImpl<Scalar,StorageIndex>::pruneL(const Index jcol, const IndexVector& perm_r, const Index pivrow, const Index nseg,
54
+ const IndexVector& segrep, BlockIndexVector repfnz, IndexVector& xprune, GlobalLU_t& glu)
55
+ {
56
+ // For each supernode-rep irep in U(*,j]
57
+ Index jsupno = glu.supno(jcol);
58
+ Index i,irep,irep1;
59
+ bool movnum, do_prune = false;
60
+ Index kmin = 0, kmax = 0, minloc, maxloc,krow;
61
+ for (i = 0; i < nseg; i++)
62
+ {
63
+ irep = segrep(i);
64
+ irep1 = irep + 1;
65
+ do_prune = false;
66
+
67
+ // Don't prune with a zero U-segment
68
+ if (repfnz(irep) == emptyIdxLU) continue;
69
+
70
+ // If a snode overlaps with the next panel, then the U-segment
71
+ // is fragmented into two parts -- irep and irep1. We should let
72
+ // pruning occur at the rep-column in irep1s snode.
73
+ if (glu.supno(irep) == glu.supno(irep1) ) continue; // don't prune
74
+
75
+ // If it has not been pruned & it has a nonz in row L(pivrow,i)
76
+ if (glu.supno(irep) != jsupno )
77
+ {
78
+ if ( xprune (irep) >= glu.xlsub(irep1) )
79
+ {
80
+ kmin = glu.xlsub(irep);
81
+ kmax = glu.xlsub(irep1) - 1;
82
+ for (krow = kmin; krow <= kmax; krow++)
83
+ {
84
+ if (glu.lsub(krow) == pivrow)
85
+ {
86
+ do_prune = true;
87
+ break;
88
+ }
89
+ }
90
+ }
91
+
92
+ if (do_prune)
93
+ {
94
+ // do a quicksort-type partition
95
+ // movnum=true means that the num values have to be exchanged
96
+ movnum = false;
97
+ if (irep == glu.xsup(glu.supno(irep)) ) // Snode of size 1
98
+ movnum = true;
99
+
100
+ while (kmin <= kmax)
101
+ {
102
+ if (perm_r(glu.lsub(kmax)) == emptyIdxLU)
103
+ kmax--;
104
+ else if ( perm_r(glu.lsub(kmin)) != emptyIdxLU)
105
+ kmin++;
106
+ else
107
+ {
108
+ // kmin below pivrow (not yet pivoted), and kmax
109
+ // above pivrow: interchange the two suscripts
110
+ std::swap(glu.lsub(kmin), glu.lsub(kmax));
111
+
112
+ // If the supernode has only one column, then we
113
+ // only keep one set of subscripts. For any subscript
114
+ // intercnahge performed, similar interchange must be
115
+ // done on the numerical values.
116
+ if (movnum)
117
+ {
118
+ minloc = glu.xlusup(irep) + ( kmin - glu.xlsub(irep) );
119
+ maxloc = glu.xlusup(irep) + ( kmax - glu.xlsub(irep) );
120
+ std::swap(glu.lusup(minloc), glu.lusup(maxloc));
121
+ }
122
+ kmin++;
123
+ kmax--;
124
+ }
125
+ } // end while
126
+
127
+ xprune(irep) = StorageIndex(kmin); //Pruning
128
+ } // end if do_prune
129
+ } // end pruning
130
+ } // End for each U-segment
131
+ }
132
+
133
+ } // end namespace internal
134
+ } // end namespace Eigen
135
+
136
+ #endif // SPARSELU_PRUNEL_H
@@ -0,0 +1,83 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsa_wakam@inria.fr>
5
+ //
6
+ // This Source Code Form is subject to the terms of the Mozilla
7
+ // Public License v. 2.0. If a copy of the MPL was not distributed
8
+ // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
+
10
+ /* This file is a modified version of heap_relax_snode.c file in SuperLU
11
+ * -- SuperLU routine (version 3.0) --
12
+ * Univ. of California Berkeley, Xerox Palo Alto Research Center,
13
+ * and Lawrence Berkeley National Lab.
14
+ * October 15, 2003
15
+ *
16
+ * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
17
+ *
18
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
19
+ * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
20
+ *
21
+ * Permission is hereby granted to use or copy this program for any
22
+ * purpose, provided the above notices are retained on all copies.
23
+ * Permission to modify the code and to distribute modified code is
24
+ * granted, provided the above notices are retained, and a notice that
25
+ * the code was modified is included with the above copyright notice.
26
+ */
27
+
28
+ #ifndef SPARSELU_RELAX_SNODE_H
29
+ #define SPARSELU_RELAX_SNODE_H
30
+
31
+ namespace Eigen {
32
+
33
+ namespace internal {
34
+
35
+ /**
36
+ * \brief Identify the initial relaxed supernodes
37
+ *
38
+ * This routine is applied to a column elimination tree.
39
+ * It assumes that the matrix has been reordered according to the postorder of the etree
40
+ * \param n the number of columns
41
+ * \param et elimination tree
42
+ * \param relax_columns Maximum number of columns allowed in a relaxed snode
43
+ * \param descendants Number of descendants of each node in the etree
44
+ * \param relax_end last column in a supernode
45
+ */
46
+ template <typename Scalar, typename StorageIndex>
47
+ void SparseLUImpl<Scalar,StorageIndex>::relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end)
48
+ {
49
+
50
+ // compute the number of descendants of each node in the etree
51
+ Index parent;
52
+ relax_end.setConstant(emptyIdxLU);
53
+ descendants.setZero();
54
+ for (Index j = 0; j < n; j++)
55
+ {
56
+ parent = et(j);
57
+ if (parent != n) // not the dummy root
58
+ descendants(parent) += descendants(j) + 1;
59
+ }
60
+ // Identify the relaxed supernodes by postorder traversal of the etree
61
+ Index snode_start; // beginning of a snode
62
+ for (Index j = 0; j < n; )
63
+ {
64
+ parent = et(j);
65
+ snode_start = j;
66
+ while ( parent != n && descendants(parent) < relax_columns )
67
+ {
68
+ j = parent;
69
+ parent = et(j);
70
+ }
71
+ // Found a supernode in postordered etree, j is the last column
72
+ relax_end(snode_start) = StorageIndex(j); // Record last column
73
+ j++;
74
+ // Search for a new leaf
75
+ while (descendants(j) != 0 && j < n) j++;
76
+ } // End postorder traversal of the etree
77
+
78
+ }
79
+
80
+ } // end namespace internal
81
+
82
+ } // end namespace Eigen
83
+ #endif
@@ -0,0 +1,745 @@
1
+ // This file is part of Eigen, a lightweight C++ template library
2
+ // for linear algebra.
3
+ //
4
+ // Copyright (C) 2012-2013 Desire Nuentsa <desire.nuentsa_wakam@inria.fr>
5
+ // Copyright (C) 2012-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_SPARSE_QR_H
12
+ #define EIGEN_SPARSE_QR_H
13
+
14
+ namespace Eigen {
15
+
16
+ template<typename MatrixType, typename OrderingType> class SparseQR;
17
+ template<typename SparseQRType> struct SparseQRMatrixQReturnType;
18
+ template<typename SparseQRType> struct SparseQRMatrixQTransposeReturnType;
19
+ template<typename SparseQRType, typename Derived> struct SparseQR_QProduct;
20
+ namespace internal {
21
+ template <typename SparseQRType> struct traits<SparseQRMatrixQReturnType<SparseQRType> >
22
+ {
23
+ typedef typename SparseQRType::MatrixType ReturnType;
24
+ typedef typename ReturnType::StorageIndex StorageIndex;
25
+ typedef typename ReturnType::StorageKind StorageKind;
26
+ enum {
27
+ RowsAtCompileTime = Dynamic,
28
+ ColsAtCompileTime = Dynamic
29
+ };
30
+ };
31
+ template <typename SparseQRType> struct traits<SparseQRMatrixQTransposeReturnType<SparseQRType> >
32
+ {
33
+ typedef typename SparseQRType::MatrixType ReturnType;
34
+ };
35
+ template <typename SparseQRType, typename Derived> struct traits<SparseQR_QProduct<SparseQRType, Derived> >
36
+ {
37
+ typedef typename Derived::PlainObject ReturnType;
38
+ };
39
+ } // End namespace internal
40
+
41
+ /**
42
+ * \ingroup SparseQR_Module
43
+ * \class SparseQR
44
+ * \brief Sparse left-looking rank-revealing QR factorization
45
+ *
46
+ * This class implements a left-looking rank-revealing QR decomposition
47
+ * of sparse matrices. When a column has a norm less than a given tolerance
48
+ * it is implicitly permuted to the end. The QR factorization thus obtained is
49
+ * given by A*P = Q*R where R is upper triangular or trapezoidal.
50
+ *
51
+ * P is the column permutation which is the product of the fill-reducing and the
52
+ * rank-revealing permutations. Use colsPermutation() to get it.
53
+ *
54
+ * Q is the orthogonal matrix represented as products of Householder reflectors.
55
+ * Use matrixQ() to get an expression and matrixQ().adjoint() to get the adjoint.
56
+ * You can then apply it to a vector.
57
+ *
58
+ * R is the sparse triangular or trapezoidal matrix. The later occurs when A is rank-deficient.
59
+ * matrixR().topLeftCorner(rank(), rank()) always returns a triangular factor of full rank.
60
+ *
61
+ * \tparam _MatrixType The type of the sparse matrix A, must be a column-major SparseMatrix<>
62
+ * \tparam _OrderingType The fill-reducing ordering method. See the \link OrderingMethods_Module
63
+ * OrderingMethods \endlink module for the list of built-in and external ordering methods.
64
+ *
65
+ * \implsparsesolverconcept
66
+ *
67
+ * \warning The input sparse matrix A must be in compressed mode (see SparseMatrix::makeCompressed()).
68
+ * \warning For complex matrices matrixQ().transpose() will actually return the adjoint matrix.
69
+ *
70
+ */
71
+ template<typename _MatrixType, typename _OrderingType>
72
+ class SparseQR : public SparseSolverBase<SparseQR<_MatrixType,_OrderingType> >
73
+ {
74
+ protected:
75
+ typedef SparseSolverBase<SparseQR<_MatrixType,_OrderingType> > Base;
76
+ using Base::m_isInitialized;
77
+ public:
78
+ using Base::_solve_impl;
79
+ typedef _MatrixType MatrixType;
80
+ typedef _OrderingType OrderingType;
81
+ typedef typename MatrixType::Scalar Scalar;
82
+ typedef typename MatrixType::RealScalar RealScalar;
83
+ typedef typename MatrixType::StorageIndex StorageIndex;
84
+ typedef SparseMatrix<Scalar,ColMajor,StorageIndex> QRMatrixType;
85
+ typedef Matrix<StorageIndex, Dynamic, 1> IndexVector;
86
+ typedef Matrix<Scalar, Dynamic, 1> ScalarVector;
87
+ typedef PermutationMatrix<Dynamic, Dynamic, StorageIndex> PermutationType;
88
+
89
+ enum {
90
+ ColsAtCompileTime = MatrixType::ColsAtCompileTime,
91
+ MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
92
+ };
93
+
94
+ public:
95
+ SparseQR () : m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false),m_isEtreeOk(false)
96
+ { }
97
+
98
+ /** Construct a QR factorization of the matrix \a mat.
99
+ *
100
+ * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()).
101
+ *
102
+ * \sa compute()
103
+ */
104
+ explicit SparseQR(const MatrixType& mat) : m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false),m_isEtreeOk(false)
105
+ {
106
+ compute(mat);
107
+ }
108
+
109
+ /** Computes the QR factorization of the sparse matrix \a mat.
110
+ *
111
+ * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()).
112
+ *
113
+ * \sa analyzePattern(), factorize()
114
+ */
115
+ void compute(const MatrixType& mat)
116
+ {
117
+ analyzePattern(mat);
118
+ factorize(mat);
119
+ }
120
+ void analyzePattern(const MatrixType& mat);
121
+ void factorize(const MatrixType& mat);
122
+
123
+ /** \returns the number of rows of the represented matrix.
124
+ */
125
+ inline Index rows() const { return m_pmat.rows(); }
126
+
127
+ /** \returns the number of columns of the represented matrix.
128
+ */
129
+ inline Index cols() const { return m_pmat.cols();}
130
+
131
+ /** \returns a const reference to the \b sparse upper triangular matrix R of the QR factorization.
132
+ * \warning The entries of the returned matrix are not sorted. This means that using it in algorithms
133
+ * expecting sorted entries will fail. This include random coefficient accesses (SpaseMatrix::coeff()),
134
+ * and coefficient-wise operations. Matrix products and triangular solves are fine though.
135
+ *
136
+ * To sort the entries, you can assign it to a row-major matrix, and if a column-major matrix
137
+ * is required, you can copy it again:
138
+ * \code
139
+ * SparseMatrix<double> R = qr.matrixR(); // column-major, not sorted!
140
+ * SparseMatrix<double,RowMajor> Rr = qr.matrixR(); // row-major, sorted
141
+ * SparseMatrix<double> Rc = Rr; // column-major, sorted
142
+ * \endcode
143
+ */
144
+ const QRMatrixType& matrixR() const { return m_R; }
145
+
146
+ /** \returns the number of non linearly dependent columns as determined by the pivoting threshold.
147
+ *
148
+ * \sa setPivotThreshold()
149
+ */
150
+ Index rank() const
151
+ {
152
+ eigen_assert(m_isInitialized && "The factorization should be called first, use compute()");
153
+ return m_nonzeropivots;
154
+ }
155
+
156
+ /** \returns an expression of the matrix Q as products of sparse Householder reflectors.
157
+ * The common usage of this function is to apply it to a dense matrix or vector
158
+ * \code
159
+ * VectorXd B1, B2;
160
+ * // Initialize B1
161
+ * B2 = matrixQ() * B1;
162
+ * \endcode
163
+ *
164
+ * To get a plain SparseMatrix representation of Q:
165
+ * \code
166
+ * SparseMatrix<double> Q;
167
+ * Q = SparseQR<SparseMatrix<double> >(A).matrixQ();
168
+ * \endcode
169
+ * Internally, this call simply performs a sparse product between the matrix Q
170
+ * and a sparse identity matrix. However, due to the fact that the sparse
171
+ * reflectors are stored unsorted, two transpositions are needed to sort
172
+ * them before performing the product.
173
+ */
174
+ SparseQRMatrixQReturnType<SparseQR> matrixQ() const
175
+ { return SparseQRMatrixQReturnType<SparseQR>(*this); }
176
+
177
+ /** \returns a const reference to the column permutation P that was applied to A such that A*P = Q*R
178
+ * It is the combination of the fill-in reducing permutation and numerical column pivoting.
179
+ */
180
+ const PermutationType& colsPermutation() const
181
+ {
182
+ eigen_assert(m_isInitialized && "Decomposition is not initialized.");
183
+ return m_outputPerm_c;
184
+ }
185
+
186
+ /** \returns A string describing the type of error.
187
+ * This method is provided to ease debugging, not to handle errors.
188
+ */
189
+ std::string lastErrorMessage() const { return m_lastError; }
190
+
191
+ /** \internal */
192
+ template<typename Rhs, typename Dest>
193
+ bool _solve_impl(const MatrixBase<Rhs> &B, MatrixBase<Dest> &dest) const
194
+ {
195
+ eigen_assert(m_isInitialized && "The factorization should be called first, use compute()");
196
+ eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix");
197
+
198
+ Index rank = this->rank();
199
+
200
+ // Compute Q^* * b;
201
+ typename Dest::PlainObject y, b;
202
+ y = this->matrixQ().adjoint() * B;
203
+ b = y;
204
+
205
+ // Solve with the triangular matrix R
206
+ y.resize((std::max<Index>)(cols(),y.rows()),y.cols());
207
+ y.topRows(rank) = this->matrixR().topLeftCorner(rank, rank).template triangularView<Upper>().solve(b.topRows(rank));
208
+ y.bottomRows(y.rows()-rank).setZero();
209
+
210
+ // Apply the column permutation
211
+ if (m_perm_c.size()) dest = colsPermutation() * y.topRows(cols());
212
+ else dest = y.topRows(cols());
213
+
214
+ m_info = Success;
215
+ return true;
216
+ }
217
+
218
+ /** Sets the threshold that is used to determine linearly dependent columns during the factorization.
219
+ *
220
+ * In practice, if during the factorization the norm of the column that has to be eliminated is below
221
+ * this threshold, then the entire column is treated as zero, and it is moved at the end.
222
+ */
223
+ void setPivotThreshold(const RealScalar& threshold)
224
+ {
225
+ m_useDefaultThreshold = false;
226
+ m_threshold = threshold;
227
+ }
228
+
229
+ /** \returns the solution X of \f$ A X = B \f$ using the current decomposition of A.
230
+ *
231
+ * \sa compute()
232
+ */
233
+ template<typename Rhs>
234
+ inline const Solve<SparseQR, Rhs> solve(const MatrixBase<Rhs>& B) const
235
+ {
236
+ eigen_assert(m_isInitialized && "The factorization should be called first, use compute()");
237
+ eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix");
238
+ return Solve<SparseQR, Rhs>(*this, B.derived());
239
+ }
240
+ template<typename Rhs>
241
+ inline const Solve<SparseQR, Rhs> solve(const SparseMatrixBase<Rhs>& B) const
242
+ {
243
+ eigen_assert(m_isInitialized && "The factorization should be called first, use compute()");
244
+ eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix");
245
+ return Solve<SparseQR, Rhs>(*this, B.derived());
246
+ }
247
+
248
+ /** \brief Reports whether previous computation was successful.
249
+ *
250
+ * \returns \c Success if computation was successful,
251
+ * \c NumericalIssue if the QR factorization reports a numerical problem
252
+ * \c InvalidInput if the input matrix is invalid
253
+ *
254
+ * \sa iparm()
255
+ */
256
+ ComputationInfo info() const
257
+ {
258
+ eigen_assert(m_isInitialized && "Decomposition is not initialized.");
259
+ return m_info;
260
+ }
261
+
262
+
263
+ /** \internal */
264
+ inline void _sort_matrix_Q()
265
+ {
266
+ if(this->m_isQSorted) return;
267
+ // The matrix Q is sorted during the transposition
268
+ SparseMatrix<Scalar, RowMajor, Index> mQrm(this->m_Q);
269
+ this->m_Q = mQrm;
270
+ this->m_isQSorted = true;
271
+ }
272
+
273
+
274
+ protected:
275
+ bool m_analysisIsok;
276
+ bool m_factorizationIsok;
277
+ mutable ComputationInfo m_info;
278
+ std::string m_lastError;
279
+ QRMatrixType m_pmat; // Temporary matrix
280
+ QRMatrixType m_R; // The triangular factor matrix
281
+ QRMatrixType m_Q; // The orthogonal reflectors
282
+ ScalarVector m_hcoeffs; // The Householder coefficients
283
+ PermutationType m_perm_c; // Fill-reducing Column permutation
284
+ PermutationType m_pivotperm; // The permutation for rank revealing
285
+ PermutationType m_outputPerm_c; // The final column permutation
286
+ RealScalar m_threshold; // Threshold to determine null Householder reflections
287
+ bool m_useDefaultThreshold; // Use default threshold
288
+ Index m_nonzeropivots; // Number of non zero pivots found
289
+ IndexVector m_etree; // Column elimination tree
290
+ IndexVector m_firstRowElt; // First element in each row
291
+ bool m_isQSorted; // whether Q is sorted or not
292
+ bool m_isEtreeOk; // whether the elimination tree match the initial input matrix
293
+
294
+ template <typename, typename > friend struct SparseQR_QProduct;
295
+
296
+ };
297
+
298
+ /** \brief Preprocessing step of a QR factorization
299
+ *
300
+ * \warning The matrix \a mat must be in compressed mode (see SparseMatrix::makeCompressed()).
301
+ *
302
+ * In this step, the fill-reducing permutation is computed and applied to the columns of A
303
+ * and the column elimination tree is computed as well. Only the sparsity pattern of \a mat is exploited.
304
+ *
305
+ * \note In this step it is assumed that there is no empty row in the matrix \a mat.
306
+ */
307
+ template <typename MatrixType, typename OrderingType>
308
+ void SparseQR<MatrixType,OrderingType>::analyzePattern(const MatrixType& mat)
309
+ {
310
+ eigen_assert(mat.isCompressed() && "SparseQR requires a sparse matrix in compressed mode. Call .makeCompressed() before passing it to SparseQR");
311
+ // Copy to a column major matrix if the input is rowmajor
312
+ typename internal::conditional<MatrixType::IsRowMajor,QRMatrixType,const MatrixType&>::type matCpy(mat);
313
+ // Compute the column fill reducing ordering
314
+ OrderingType ord;
315
+ ord(matCpy, m_perm_c);
316
+ Index n = mat.cols();
317
+ Index m = mat.rows();
318
+ Index diagSize = (std::min)(m,n);
319
+
320
+ if (!m_perm_c.size())
321
+ {
322
+ m_perm_c.resize(n);
323
+ m_perm_c.indices().setLinSpaced(n, 0,StorageIndex(n-1));
324
+ }
325
+
326
+ // Compute the column elimination tree of the permuted matrix
327
+ m_outputPerm_c = m_perm_c.inverse();
328
+ internal::coletree(matCpy, m_etree, m_firstRowElt, m_outputPerm_c.indices().data());
329
+ m_isEtreeOk = true;
330
+
331
+ m_R.resize(m, n);
332
+ m_Q.resize(m, diagSize);
333
+
334
+ // Allocate space for nonzero elements : rough estimation
335
+ m_R.reserve(2*mat.nonZeros()); //FIXME Get a more accurate estimation through symbolic factorization with the etree
336
+ m_Q.reserve(2*mat.nonZeros());
337
+ m_hcoeffs.resize(diagSize);
338
+ m_analysisIsok = true;
339
+ }
340
+
341
+ /** \brief Performs the numerical QR factorization of the input matrix
342
+ *
343
+ * The function SparseQR::analyzePattern(const MatrixType&) must have been called beforehand with
344
+ * a matrix having the same sparsity pattern than \a mat.
345
+ *
346
+ * \param mat The sparse column-major matrix
347
+ */
348
+ template <typename MatrixType, typename OrderingType>
349
+ void SparseQR<MatrixType,OrderingType>::factorize(const MatrixType& mat)
350
+ {
351
+ using std::abs;
352
+
353
+ eigen_assert(m_analysisIsok && "analyzePattern() should be called before this step");
354
+ StorageIndex m = StorageIndex(mat.rows());
355
+ StorageIndex n = StorageIndex(mat.cols());
356
+ StorageIndex diagSize = (std::min)(m,n);
357
+ IndexVector mark((std::max)(m,n)); mark.setConstant(-1); // Record the visited nodes
358
+ IndexVector Ridx(n), Qidx(m); // Store temporarily the row indexes for the current column of R and Q
359
+ Index nzcolR, nzcolQ; // Number of nonzero for the current column of R and Q
360
+ ScalarVector tval(m); // The dense vector used to compute the current column
361
+ RealScalar pivotThreshold = m_threshold;
362
+
363
+ m_R.setZero();
364
+ m_Q.setZero();
365
+ m_pmat = mat;
366
+ if(!m_isEtreeOk)
367
+ {
368
+ m_outputPerm_c = m_perm_c.inverse();
369
+ internal::coletree(m_pmat, m_etree, m_firstRowElt, m_outputPerm_c.indices().data());
370
+ m_isEtreeOk = true;
371
+ }
372
+
373
+ m_pmat.uncompress(); // To have the innerNonZeroPtr allocated
374
+
375
+ // Apply the fill-in reducing permutation lazily:
376
+ {
377
+ // If the input is row major, copy the original column indices,
378
+ // otherwise directly use the input matrix
379
+ //
380
+ IndexVector originalOuterIndicesCpy;
381
+ const StorageIndex *originalOuterIndices = mat.outerIndexPtr();
382
+ if(MatrixType::IsRowMajor)
383
+ {
384
+ originalOuterIndicesCpy = IndexVector::Map(m_pmat.outerIndexPtr(),n+1);
385
+ originalOuterIndices = originalOuterIndicesCpy.data();
386
+ }
387
+
388
+ for (int i = 0; i < n; i++)
389
+ {
390
+ Index p = m_perm_c.size() ? m_perm_c.indices()(i) : i;
391
+ m_pmat.outerIndexPtr()[p] = originalOuterIndices[i];
392
+ m_pmat.innerNonZeroPtr()[p] = originalOuterIndices[i+1] - originalOuterIndices[i];
393
+ }
394
+ }
395
+
396
+ /* Compute the default threshold as in MatLab, see:
397
+ * Tim Davis, "Algorithm 915, SuiteSparseQR: Multifrontal Multithreaded Rank-Revealing
398
+ * Sparse QR Factorization, ACM Trans. on Math. Soft. 38(1), 2011, Page 8:3
399
+ */
400
+ if(m_useDefaultThreshold)
401
+ {
402
+ RealScalar max2Norm = 0.0;
403
+ for (int j = 0; j < n; j++) max2Norm = numext::maxi(max2Norm, m_pmat.col(j).norm());
404
+ if(max2Norm==RealScalar(0))
405
+ max2Norm = RealScalar(1);
406
+ pivotThreshold = 20 * (m + n) * max2Norm * NumTraits<RealScalar>::epsilon();
407
+ }
408
+
409
+ // Initialize the numerical permutation
410
+ m_pivotperm.setIdentity(n);
411
+
412
+ StorageIndex nonzeroCol = 0; // Record the number of valid pivots
413
+ m_Q.startVec(0);
414
+
415
+ // Left looking rank-revealing QR factorization: compute a column of R and Q at a time
416
+ for (StorageIndex col = 0; col < n; ++col)
417
+ {
418
+ mark.setConstant(-1);
419
+ m_R.startVec(col);
420
+ mark(nonzeroCol) = col;
421
+ Qidx(0) = nonzeroCol;
422
+ nzcolR = 0; nzcolQ = 1;
423
+ bool found_diag = nonzeroCol>=m;
424
+ tval.setZero();
425
+
426
+ // Symbolic factorization: find the nonzero locations of the column k of the factors R and Q, i.e.,
427
+ // all the nodes (with indexes lower than rank) reachable through the column elimination tree (etree) rooted at node k.
428
+ // Note: if the diagonal entry does not exist, then its contribution must be explicitly added,
429
+ // thus the trick with found_diag that permits to do one more iteration on the diagonal element if this one has not been found.
430
+ for (typename QRMatrixType::InnerIterator itp(m_pmat, col); itp || !found_diag; ++itp)
431
+ {
432
+ StorageIndex curIdx = nonzeroCol;
433
+ if(itp) curIdx = StorageIndex(itp.row());
434
+ if(curIdx == nonzeroCol) found_diag = true;
435
+
436
+ // Get the nonzeros indexes of the current column of R
437
+ StorageIndex st = m_firstRowElt(curIdx); // The traversal of the etree starts here
438
+ if (st < 0 )
439
+ {
440
+ m_lastError = "Empty row found during numerical factorization";
441
+ m_info = InvalidInput;
442
+ return;
443
+ }
444
+
445
+ // Traverse the etree
446
+ Index bi = nzcolR;
447
+ for (; mark(st) != col; st = m_etree(st))
448
+ {
449
+ Ridx(nzcolR) = st; // Add this row to the list,
450
+ mark(st) = col; // and mark this row as visited
451
+ nzcolR++;
452
+ }
453
+
454
+ // Reverse the list to get the topological ordering
455
+ Index nt = nzcolR-bi;
456
+ for(Index i = 0; i < nt/2; i++) std::swap(Ridx(bi+i), Ridx(nzcolR-i-1));
457
+
458
+ // Copy the current (curIdx,pcol) value of the input matrix
459
+ if(itp) tval(curIdx) = itp.value();
460
+ else tval(curIdx) = Scalar(0);
461
+
462
+ // Compute the pattern of Q(:,k)
463
+ if(curIdx > nonzeroCol && mark(curIdx) != col )
464
+ {
465
+ Qidx(nzcolQ) = curIdx; // Add this row to the pattern of Q,
466
+ mark(curIdx) = col; // and mark it as visited
467
+ nzcolQ++;
468
+ }
469
+ }
470
+
471
+ // Browse all the indexes of R(:,col) in reverse order
472
+ for (Index i = nzcolR-1; i >= 0; i--)
473
+ {
474
+ Index curIdx = Ridx(i);
475
+
476
+ // Apply the curIdx-th householder vector to the current column (temporarily stored into tval)
477
+ Scalar tdot(0);
478
+
479
+ // First compute q' * tval
480
+ tdot = m_Q.col(curIdx).dot(tval);
481
+
482
+ tdot *= m_hcoeffs(curIdx);
483
+
484
+ // Then update tval = tval - q * tau
485
+ // FIXME: tval -= tdot * m_Q.col(curIdx) should amount to the same (need to check/add support for efficient "dense ?= sparse")
486
+ for (typename QRMatrixType::InnerIterator itq(m_Q, curIdx); itq; ++itq)
487
+ tval(itq.row()) -= itq.value() * tdot;
488
+
489
+ // Detect fill-in for the current column of Q
490
+ if(m_etree(Ridx(i)) == nonzeroCol)
491
+ {
492
+ for (typename QRMatrixType::InnerIterator itq(m_Q, curIdx); itq; ++itq)
493
+ {
494
+ StorageIndex iQ = StorageIndex(itq.row());
495
+ if (mark(iQ) != col)
496
+ {
497
+ Qidx(nzcolQ++) = iQ; // Add this row to the pattern of Q,
498
+ mark(iQ) = col; // and mark it as visited
499
+ }
500
+ }
501
+ }
502
+ } // End update current column
503
+
504
+ Scalar tau = RealScalar(0);
505
+ RealScalar beta = 0;
506
+
507
+ if(nonzeroCol < diagSize)
508
+ {
509
+ // Compute the Householder reflection that eliminate the current column
510
+ // FIXME this step should call the Householder module.
511
+ Scalar c0 = nzcolQ ? tval(Qidx(0)) : Scalar(0);
512
+
513
+ // First, the squared norm of Q((col+1):m, col)
514
+ RealScalar sqrNorm = 0.;
515
+ for (Index itq = 1; itq < nzcolQ; ++itq) sqrNorm += numext::abs2(tval(Qidx(itq)));
516
+ if(sqrNorm == RealScalar(0) && numext::imag(c0) == RealScalar(0))
517
+ {
518
+ beta = numext::real(c0);
519
+ tval(Qidx(0)) = 1;
520
+ }
521
+ else
522
+ {
523
+ using std::sqrt;
524
+ beta = sqrt(numext::abs2(c0) + sqrNorm);
525
+ if(numext::real(c0) >= RealScalar(0))
526
+ beta = -beta;
527
+ tval(Qidx(0)) = 1;
528
+ for (Index itq = 1; itq < nzcolQ; ++itq)
529
+ tval(Qidx(itq)) /= (c0 - beta);
530
+ tau = numext::conj((beta-c0) / beta);
531
+
532
+ }
533
+ }
534
+
535
+ // Insert values in R
536
+ for (Index i = nzcolR-1; i >= 0; i--)
537
+ {
538
+ Index curIdx = Ridx(i);
539
+ if(curIdx < nonzeroCol)
540
+ {
541
+ m_R.insertBackByOuterInnerUnordered(col, curIdx) = tval(curIdx);
542
+ tval(curIdx) = Scalar(0.);
543
+ }
544
+ }
545
+
546
+ if(nonzeroCol < diagSize && abs(beta) >= pivotThreshold)
547
+ {
548
+ m_R.insertBackByOuterInner(col, nonzeroCol) = beta;
549
+ // The householder coefficient
550
+ m_hcoeffs(nonzeroCol) = tau;
551
+ // Record the householder reflections
552
+ for (Index itq = 0; itq < nzcolQ; ++itq)
553
+ {
554
+ Index iQ = Qidx(itq);
555
+ m_Q.insertBackByOuterInnerUnordered(nonzeroCol,iQ) = tval(iQ);
556
+ tval(iQ) = Scalar(0.);
557
+ }
558
+ nonzeroCol++;
559
+ if(nonzeroCol<diagSize)
560
+ m_Q.startVec(nonzeroCol);
561
+ }
562
+ else
563
+ {
564
+ // Zero pivot found: move implicitly this column to the end
565
+ for (Index j = nonzeroCol; j < n-1; j++)
566
+ std::swap(m_pivotperm.indices()(j), m_pivotperm.indices()[j+1]);
567
+
568
+ // Recompute the column elimination tree
569
+ internal::coletree(m_pmat, m_etree, m_firstRowElt, m_pivotperm.indices().data());
570
+ m_isEtreeOk = false;
571
+ }
572
+ }
573
+
574
+ m_hcoeffs.tail(diagSize-nonzeroCol).setZero();
575
+
576
+ // Finalize the column pointers of the sparse matrices R and Q
577
+ m_Q.finalize();
578
+ m_Q.makeCompressed();
579
+ m_R.finalize();
580
+ m_R.makeCompressed();
581
+ m_isQSorted = false;
582
+
583
+ m_nonzeropivots = nonzeroCol;
584
+
585
+ if(nonzeroCol<n)
586
+ {
587
+ // Permute the triangular factor to put the 'dead' columns to the end
588
+ QRMatrixType tempR(m_R);
589
+ m_R = tempR * m_pivotperm;
590
+
591
+ // Update the column permutation
592
+ m_outputPerm_c = m_outputPerm_c * m_pivotperm;
593
+ }
594
+
595
+ m_isInitialized = true;
596
+ m_factorizationIsok = true;
597
+ m_info = Success;
598
+ }
599
+
600
+ template <typename SparseQRType, typename Derived>
601
+ struct SparseQR_QProduct : ReturnByValue<SparseQR_QProduct<SparseQRType, Derived> >
602
+ {
603
+ typedef typename SparseQRType::QRMatrixType MatrixType;
604
+ typedef typename SparseQRType::Scalar Scalar;
605
+ // Get the references
606
+ SparseQR_QProduct(const SparseQRType& qr, const Derived& other, bool transpose) :
607
+ m_qr(qr),m_other(other),m_transpose(transpose) {}
608
+ inline Index rows() const { return m_qr.matrixQ().rows(); }
609
+ inline Index cols() const { return m_other.cols(); }
610
+
611
+ // Assign to a vector
612
+ template<typename DesType>
613
+ void evalTo(DesType& res) const
614
+ {
615
+ Index m = m_qr.rows();
616
+ Index n = m_qr.cols();
617
+ Index diagSize = (std::min)(m,n);
618
+ res = m_other;
619
+ if (m_transpose)
620
+ {
621
+ eigen_assert(m_qr.m_Q.rows() == m_other.rows() && "Non conforming object sizes");
622
+ //Compute res = Q' * other column by column
623
+ for(Index j = 0; j < res.cols(); j++){
624
+ for (Index k = 0; k < diagSize; k++)
625
+ {
626
+ Scalar tau = Scalar(0);
627
+ tau = m_qr.m_Q.col(k).dot(res.col(j));
628
+ if(tau==Scalar(0)) continue;
629
+ tau = tau * m_qr.m_hcoeffs(k);
630
+ res.col(j) -= tau * m_qr.m_Q.col(k);
631
+ }
632
+ }
633
+ }
634
+ else
635
+ {
636
+ eigen_assert(m_qr.matrixQ().cols() == m_other.rows() && "Non conforming object sizes");
637
+
638
+ res.conservativeResize(rows(), cols());
639
+
640
+ // Compute res = Q * other column by column
641
+ for(Index j = 0; j < res.cols(); j++)
642
+ {
643
+ for (Index k = diagSize-1; k >=0; k--)
644
+ {
645
+ Scalar tau = Scalar(0);
646
+ tau = m_qr.m_Q.col(k).dot(res.col(j));
647
+ if(tau==Scalar(0)) continue;
648
+ tau = tau * numext::conj(m_qr.m_hcoeffs(k));
649
+ res.col(j) -= tau * m_qr.m_Q.col(k);
650
+ }
651
+ }
652
+ }
653
+ }
654
+
655
+ const SparseQRType& m_qr;
656
+ const Derived& m_other;
657
+ bool m_transpose; // TODO this actually means adjoint
658
+ };
659
+
660
+ template<typename SparseQRType>
661
+ struct SparseQRMatrixQReturnType : public EigenBase<SparseQRMatrixQReturnType<SparseQRType> >
662
+ {
663
+ typedef typename SparseQRType::Scalar Scalar;
664
+ typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
665
+ enum {
666
+ RowsAtCompileTime = Dynamic,
667
+ ColsAtCompileTime = Dynamic
668
+ };
669
+ explicit SparseQRMatrixQReturnType(const SparseQRType& qr) : m_qr(qr) {}
670
+ template<typename Derived>
671
+ SparseQR_QProduct<SparseQRType, Derived> operator*(const MatrixBase<Derived>& other)
672
+ {
673
+ return SparseQR_QProduct<SparseQRType,Derived>(m_qr,other.derived(),false);
674
+ }
675
+ // To use for operations with the adjoint of Q
676
+ SparseQRMatrixQTransposeReturnType<SparseQRType> adjoint() const
677
+ {
678
+ return SparseQRMatrixQTransposeReturnType<SparseQRType>(m_qr);
679
+ }
680
+ inline Index rows() const { return m_qr.rows(); }
681
+ inline Index cols() const { return m_qr.rows(); }
682
+ // To use for operations with the transpose of Q FIXME this is the same as adjoint at the moment
683
+ SparseQRMatrixQTransposeReturnType<SparseQRType> transpose() const
684
+ {
685
+ return SparseQRMatrixQTransposeReturnType<SparseQRType>(m_qr);
686
+ }
687
+ const SparseQRType& m_qr;
688
+ };
689
+
690
+ // TODO this actually represents the adjoint of Q
691
+ template<typename SparseQRType>
692
+ struct SparseQRMatrixQTransposeReturnType
693
+ {
694
+ explicit SparseQRMatrixQTransposeReturnType(const SparseQRType& qr) : m_qr(qr) {}
695
+ template<typename Derived>
696
+ SparseQR_QProduct<SparseQRType,Derived> operator*(const MatrixBase<Derived>& other)
697
+ {
698
+ return SparseQR_QProduct<SparseQRType,Derived>(m_qr,other.derived(), true);
699
+ }
700
+ const SparseQRType& m_qr;
701
+ };
702
+
703
+ namespace internal {
704
+
705
+ template<typename SparseQRType>
706
+ struct evaluator_traits<SparseQRMatrixQReturnType<SparseQRType> >
707
+ {
708
+ typedef typename SparseQRType::MatrixType MatrixType;
709
+ typedef typename storage_kind_to_evaluator_kind<typename MatrixType::StorageKind>::Kind Kind;
710
+ typedef SparseShape Shape;
711
+ };
712
+
713
+ template< typename DstXprType, typename SparseQRType>
714
+ struct Assignment<DstXprType, SparseQRMatrixQReturnType<SparseQRType>, internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>, Sparse2Sparse>
715
+ {
716
+ typedef SparseQRMatrixQReturnType<SparseQRType> SrcXprType;
717
+ typedef typename DstXprType::Scalar Scalar;
718
+ typedef typename DstXprType::StorageIndex StorageIndex;
719
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &/*func*/)
720
+ {
721
+ typename DstXprType::PlainObject idMat(src.rows(), src.cols());
722
+ idMat.setIdentity();
723
+ // Sort the sparse householder reflectors if needed
724
+ const_cast<SparseQRType *>(&src.m_qr)->_sort_matrix_Q();
725
+ dst = SparseQR_QProduct<SparseQRType, DstXprType>(src.m_qr, idMat, false);
726
+ }
727
+ };
728
+
729
+ template< typename DstXprType, typename SparseQRType>
730
+ struct Assignment<DstXprType, SparseQRMatrixQReturnType<SparseQRType>, internal::assign_op<typename DstXprType::Scalar,typename DstXprType::Scalar>, Sparse2Dense>
731
+ {
732
+ typedef SparseQRMatrixQReturnType<SparseQRType> SrcXprType;
733
+ typedef typename DstXprType::Scalar Scalar;
734
+ typedef typename DstXprType::StorageIndex StorageIndex;
735
+ static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar,Scalar> &/*func*/)
736
+ {
737
+ dst = src.m_qr.matrixQ() * DstXprType::Identity(src.m_qr.rows(), src.m_qr.rows());
738
+ }
739
+ };
740
+
741
+ } // end namespace internal
742
+
743
+ } // end namespace Eigen
744
+
745
+ #endif