@smake/eigen 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/README.md +1 -1
  2. package/eigen/Eigen/AccelerateSupport +52 -0
  3. package/eigen/Eigen/Cholesky +18 -21
  4. package/eigen/Eigen/CholmodSupport +28 -28
  5. package/eigen/Eigen/Core +235 -326
  6. package/eigen/Eigen/Eigenvalues +16 -14
  7. package/eigen/Eigen/Geometry +21 -24
  8. package/eigen/Eigen/Householder +9 -8
  9. package/eigen/Eigen/IterativeLinearSolvers +8 -4
  10. package/eigen/Eigen/Jacobi +14 -14
  11. package/eigen/Eigen/KLUSupport +43 -0
  12. package/eigen/Eigen/LU +16 -20
  13. package/eigen/Eigen/MetisSupport +12 -12
  14. package/eigen/Eigen/OrderingMethods +54 -54
  15. package/eigen/Eigen/PaStiXSupport +23 -20
  16. package/eigen/Eigen/PardisoSupport +17 -14
  17. package/eigen/Eigen/QR +18 -21
  18. package/eigen/Eigen/QtAlignedMalloc +5 -13
  19. package/eigen/Eigen/SPQRSupport +21 -14
  20. package/eigen/Eigen/SVD +23 -18
  21. package/eigen/Eigen/Sparse +1 -4
  22. package/eigen/Eigen/SparseCholesky +18 -23
  23. package/eigen/Eigen/SparseCore +18 -17
  24. package/eigen/Eigen/SparseLU +12 -8
  25. package/eigen/Eigen/SparseQR +16 -14
  26. package/eigen/Eigen/StdDeque +5 -2
  27. package/eigen/Eigen/StdList +5 -2
  28. package/eigen/Eigen/StdVector +5 -2
  29. package/eigen/Eigen/SuperLUSupport +30 -24
  30. package/eigen/Eigen/ThreadPool +80 -0
  31. package/eigen/Eigen/UmfPackSupport +19 -17
  32. package/eigen/Eigen/Version +14 -0
  33. package/eigen/Eigen/src/AccelerateSupport/AccelerateSupport.h +423 -0
  34. package/eigen/Eigen/src/AccelerateSupport/InternalHeaderCheck.h +3 -0
  35. package/eigen/Eigen/src/Cholesky/InternalHeaderCheck.h +3 -0
  36. package/eigen/Eigen/src/Cholesky/LDLT.h +377 -401
  37. package/eigen/Eigen/src/Cholesky/LLT.h +332 -360
  38. package/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h +81 -56
  39. package/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +620 -521
  40. package/eigen/Eigen/src/CholmodSupport/InternalHeaderCheck.h +3 -0
  41. package/eigen/Eigen/src/Core/ArithmeticSequence.h +239 -0
  42. package/eigen/Eigen/src/Core/Array.h +341 -294
  43. package/eigen/Eigen/src/Core/ArrayBase.h +190 -203
  44. package/eigen/Eigen/src/Core/ArrayWrapper.h +127 -171
  45. package/eigen/Eigen/src/Core/Assign.h +30 -40
  46. package/eigen/Eigen/src/Core/AssignEvaluator.h +711 -589
  47. package/eigen/Eigen/src/Core/Assign_MKL.h +130 -125
  48. package/eigen/Eigen/src/Core/BandMatrix.h +268 -283
  49. package/eigen/Eigen/src/Core/Block.h +375 -398
  50. package/eigen/Eigen/src/Core/CommaInitializer.h +86 -97
  51. package/eigen/Eigen/src/Core/ConditionEstimator.h +51 -53
  52. package/eigen/Eigen/src/Core/CoreEvaluators.h +1356 -1026
  53. package/eigen/Eigen/src/Core/CoreIterators.h +73 -59
  54. package/eigen/Eigen/src/Core/CwiseBinaryOp.h +114 -132
  55. package/eigen/Eigen/src/Core/CwiseNullaryOp.h +726 -617
  56. package/eigen/Eigen/src/Core/CwiseTernaryOp.h +77 -103
  57. package/eigen/Eigen/src/Core/CwiseUnaryOp.h +56 -68
  58. package/eigen/Eigen/src/Core/CwiseUnaryView.h +132 -95
  59. package/eigen/Eigen/src/Core/DenseBase.h +632 -571
  60. package/eigen/Eigen/src/Core/DenseCoeffsBase.h +511 -624
  61. package/eigen/Eigen/src/Core/DenseStorage.h +512 -509
  62. package/eigen/Eigen/src/Core/DeviceWrapper.h +153 -0
  63. package/eigen/Eigen/src/Core/Diagonal.h +169 -210
  64. package/eigen/Eigen/src/Core/DiagonalMatrix.h +351 -274
  65. package/eigen/Eigen/src/Core/DiagonalProduct.h +12 -10
  66. package/eigen/Eigen/src/Core/Dot.h +172 -222
  67. package/eigen/Eigen/src/Core/EigenBase.h +75 -85
  68. package/eigen/Eigen/src/Core/Fill.h +138 -0
  69. package/eigen/Eigen/src/Core/FindCoeff.h +464 -0
  70. package/eigen/Eigen/src/Core/ForceAlignedAccess.h +90 -109
  71. package/eigen/Eigen/src/Core/Fuzzy.h +82 -105
  72. package/eigen/Eigen/src/Core/GeneralProduct.h +327 -263
  73. package/eigen/Eigen/src/Core/GenericPacketMath.h +1472 -360
  74. package/eigen/Eigen/src/Core/GlobalFunctions.h +194 -151
  75. package/eigen/Eigen/src/Core/IO.h +147 -139
  76. package/eigen/Eigen/src/Core/IndexedView.h +321 -0
  77. package/eigen/Eigen/src/Core/InnerProduct.h +260 -0
  78. package/eigen/Eigen/src/Core/InternalHeaderCheck.h +3 -0
  79. package/eigen/Eigen/src/Core/Inverse.h +56 -66
  80. package/eigen/Eigen/src/Core/Map.h +124 -142
  81. package/eigen/Eigen/src/Core/MapBase.h +256 -281
  82. package/eigen/Eigen/src/Core/MathFunctions.h +1620 -938
  83. package/eigen/Eigen/src/Core/MathFunctionsImpl.h +233 -71
  84. package/eigen/Eigen/src/Core/Matrix.h +491 -416
  85. package/eigen/Eigen/src/Core/MatrixBase.h +468 -453
  86. package/eigen/Eigen/src/Core/NestByValue.h +66 -85
  87. package/eigen/Eigen/src/Core/NoAlias.h +79 -85
  88. package/eigen/Eigen/src/Core/NumTraits.h +235 -148
  89. package/eigen/Eigen/src/Core/PartialReduxEvaluator.h +253 -0
  90. package/eigen/Eigen/src/Core/PermutationMatrix.h +461 -511
  91. package/eigen/Eigen/src/Core/PlainObjectBase.h +871 -894
  92. package/eigen/Eigen/src/Core/Product.h +260 -139
  93. package/eigen/Eigen/src/Core/ProductEvaluators.h +863 -714
  94. package/eigen/Eigen/src/Core/Random.h +161 -136
  95. package/eigen/Eigen/src/Core/RandomImpl.h +262 -0
  96. package/eigen/Eigen/src/Core/RealView.h +250 -0
  97. package/eigen/Eigen/src/Core/Redux.h +366 -336
  98. package/eigen/Eigen/src/Core/Ref.h +308 -209
  99. package/eigen/Eigen/src/Core/Replicate.h +94 -106
  100. package/eigen/Eigen/src/Core/Reshaped.h +398 -0
  101. package/eigen/Eigen/src/Core/ReturnByValue.h +49 -55
  102. package/eigen/Eigen/src/Core/Reverse.h +136 -145
  103. package/eigen/Eigen/src/Core/Select.h +70 -140
  104. package/eigen/Eigen/src/Core/SelfAdjointView.h +262 -285
  105. package/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +23 -20
  106. package/eigen/Eigen/src/Core/SkewSymmetricMatrix3.h +382 -0
  107. package/eigen/Eigen/src/Core/Solve.h +97 -111
  108. package/eigen/Eigen/src/Core/SolveTriangular.h +131 -129
  109. package/eigen/Eigen/src/Core/SolverBase.h +138 -101
  110. package/eigen/Eigen/src/Core/StableNorm.h +156 -160
  111. package/eigen/Eigen/src/Core/StlIterators.h +619 -0
  112. package/eigen/Eigen/src/Core/Stride.h +91 -88
  113. package/eigen/Eigen/src/Core/Swap.h +70 -38
  114. package/eigen/Eigen/src/Core/Transpose.h +295 -273
  115. package/eigen/Eigen/src/Core/Transpositions.h +272 -317
  116. package/eigen/Eigen/src/Core/TriangularMatrix.h +670 -755
  117. package/eigen/Eigen/src/Core/VectorBlock.h +59 -72
  118. package/eigen/Eigen/src/Core/VectorwiseOp.h +668 -630
  119. package/eigen/Eigen/src/Core/Visitor.h +480 -216
  120. package/eigen/Eigen/src/Core/arch/AVX/Complex.h +407 -293
  121. package/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +79 -388
  122. package/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +2935 -491
  123. package/eigen/Eigen/src/Core/arch/AVX/Reductions.h +353 -0
  124. package/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +279 -22
  125. package/eigen/Eigen/src/Core/arch/AVX512/Complex.h +472 -0
  126. package/eigen/Eigen/src/Core/arch/AVX512/GemmKernel.h +1245 -0
  127. package/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +85 -333
  128. package/eigen/Eigen/src/Core/arch/AVX512/MathFunctionsFP16.h +75 -0
  129. package/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +2490 -649
  130. package/eigen/Eigen/src/Core/arch/AVX512/PacketMathFP16.h +1413 -0
  131. package/eigen/Eigen/src/Core/arch/AVX512/Reductions.h +297 -0
  132. package/eigen/Eigen/src/Core/arch/AVX512/TrsmKernel.h +1167 -0
  133. package/eigen/Eigen/src/Core/arch/AVX512/TrsmUnrolls.inc +1219 -0
  134. package/eigen/Eigen/src/Core/arch/AVX512/TypeCasting.h +277 -0
  135. package/eigen/Eigen/src/Core/arch/AVX512/TypeCastingFP16.h +130 -0
  136. package/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +521 -298
  137. package/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +39 -280
  138. package/eigen/Eigen/src/Core/arch/AltiVec/MatrixProduct.h +3686 -0
  139. package/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductCommon.h +205 -0
  140. package/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMA.h +901 -0
  141. package/eigen/Eigen/src/Core/arch/AltiVec/MatrixProductMMAbfloat16.h +742 -0
  142. package/eigen/Eigen/src/Core/arch/AltiVec/MatrixVectorProduct.inc +2818 -0
  143. package/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +3391 -723
  144. package/eigen/Eigen/src/Core/arch/AltiVec/TypeCasting.h +153 -0
  145. package/eigen/Eigen/src/Core/arch/Default/BFloat16.h +866 -0
  146. package/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +113 -14
  147. package/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctions.h +2634 -0
  148. package/eigen/Eigen/src/Core/arch/Default/GenericPacketMathFunctionsFwd.h +227 -0
  149. package/eigen/Eigen/src/Core/arch/Default/Half.h +1091 -0
  150. package/eigen/Eigen/src/Core/arch/Default/Settings.h +11 -13
  151. package/eigen/Eigen/src/Core/arch/GPU/Complex.h +244 -0
  152. package/eigen/Eigen/src/Core/arch/GPU/MathFunctions.h +104 -0
  153. package/eigen/Eigen/src/Core/arch/GPU/PacketMath.h +1712 -0
  154. package/eigen/Eigen/src/Core/arch/GPU/Tuple.h +268 -0
  155. package/eigen/Eigen/src/Core/arch/GPU/TypeCasting.h +77 -0
  156. package/eigen/Eigen/src/Core/arch/HIP/hcc/math_constants.h +23 -0
  157. package/eigen/Eigen/src/Core/arch/HVX/PacketMath.h +1088 -0
  158. package/eigen/Eigen/src/Core/arch/LSX/Complex.h +520 -0
  159. package/eigen/Eigen/src/Core/arch/LSX/GeneralBlockPanelKernel.h +23 -0
  160. package/eigen/Eigen/src/Core/arch/LSX/MathFunctions.h +43 -0
  161. package/eigen/Eigen/src/Core/arch/LSX/PacketMath.h +2866 -0
  162. package/eigen/Eigen/src/Core/arch/LSX/TypeCasting.h +526 -0
  163. package/eigen/Eigen/src/Core/arch/MSA/Complex.h +620 -0
  164. package/eigen/Eigen/src/Core/arch/MSA/MathFunctions.h +379 -0
  165. package/eigen/Eigen/src/Core/arch/MSA/PacketMath.h +1237 -0
  166. package/eigen/Eigen/src/Core/arch/NEON/Complex.h +531 -289
  167. package/eigen/Eigen/src/Core/arch/NEON/GeneralBlockPanelKernel.h +243 -0
  168. package/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +50 -73
  169. package/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +5915 -579
  170. package/eigen/Eigen/src/Core/arch/NEON/TypeCasting.h +1642 -0
  171. package/eigen/Eigen/src/Core/arch/NEON/UnaryFunctors.h +57 -0
  172. package/eigen/Eigen/src/Core/arch/SSE/Complex.h +366 -334
  173. package/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +40 -514
  174. package/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +2164 -675
  175. package/eigen/Eigen/src/Core/arch/SSE/Reductions.h +324 -0
  176. package/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +188 -35
  177. package/eigen/Eigen/src/Core/arch/SVE/MathFunctions.h +48 -0
  178. package/eigen/Eigen/src/Core/arch/SVE/PacketMath.h +674 -0
  179. package/eigen/Eigen/src/Core/arch/SVE/TypeCasting.h +52 -0
  180. package/eigen/Eigen/src/Core/arch/SYCL/InteropHeaders.h +227 -0
  181. package/eigen/Eigen/src/Core/arch/SYCL/MathFunctions.h +303 -0
  182. package/eigen/Eigen/src/Core/arch/SYCL/PacketMath.h +576 -0
  183. package/eigen/Eigen/src/Core/arch/SYCL/TypeCasting.h +83 -0
  184. package/eigen/Eigen/src/Core/arch/ZVector/Complex.h +434 -261
  185. package/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +160 -53
  186. package/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +1073 -605
  187. package/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +123 -117
  188. package/eigen/Eigen/src/Core/functors/BinaryFunctors.h +594 -322
  189. package/eigen/Eigen/src/Core/functors/NullaryFunctors.h +204 -118
  190. package/eigen/Eigen/src/Core/functors/StlFunctors.h +110 -97
  191. package/eigen/Eigen/src/Core/functors/TernaryFunctors.h +34 -7
  192. package/eigen/Eigen/src/Core/functors/UnaryFunctors.h +1158 -530
  193. package/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +2329 -1333
  194. package/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +328 -364
  195. package/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +191 -178
  196. package/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +85 -82
  197. package/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +154 -73
  198. package/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +396 -542
  199. package/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +80 -77
  200. package/eigen/Eigen/src/Core/products/Parallelizer.h +208 -92
  201. package/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +331 -375
  202. package/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +206 -224
  203. package/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +139 -146
  204. package/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +58 -61
  205. package/eigen/Eigen/src/Core/products/SelfadjointProduct.h +71 -71
  206. package/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +48 -46
  207. package/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +294 -369
  208. package/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +246 -238
  209. package/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +244 -247
  210. package/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +212 -192
  211. package/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +328 -275
  212. package/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +108 -109
  213. package/eigen/Eigen/src/Core/products/TriangularSolverVector.h +70 -93
  214. package/eigen/Eigen/src/Core/util/Assert.h +158 -0
  215. package/eigen/Eigen/src/Core/util/BlasUtil.h +413 -290
  216. package/eigen/Eigen/src/Core/util/ConfigureVectorization.h +543 -0
  217. package/eigen/Eigen/src/Core/util/Constants.h +314 -263
  218. package/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +130 -78
  219. package/eigen/Eigen/src/Core/util/EmulateArray.h +270 -0
  220. package/eigen/Eigen/src/Core/util/ForwardDeclarations.h +450 -224
  221. package/eigen/Eigen/src/Core/util/GpuHipCudaDefines.inc +101 -0
  222. package/eigen/Eigen/src/Core/util/GpuHipCudaUndefines.inc +45 -0
  223. package/eigen/Eigen/src/Core/util/IndexedViewHelper.h +487 -0
  224. package/eigen/Eigen/src/Core/util/IntegralConstant.h +279 -0
  225. package/eigen/Eigen/src/Core/util/MKL_support.h +39 -30
  226. package/eigen/Eigen/src/Core/util/Macros.h +939 -646
  227. package/eigen/Eigen/src/Core/util/MaxSizeVector.h +139 -0
  228. package/eigen/Eigen/src/Core/util/Memory.h +1042 -650
  229. package/eigen/Eigen/src/Core/util/Meta.h +618 -426
  230. package/eigen/Eigen/src/Core/util/MoreMeta.h +638 -0
  231. package/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +32 -19
  232. package/eigen/Eigen/src/Core/util/ReshapedHelper.h +51 -0
  233. package/eigen/Eigen/src/Core/util/Serializer.h +209 -0
  234. package/eigen/Eigen/src/Core/util/StaticAssert.h +51 -164
  235. package/eigen/Eigen/src/Core/util/SymbolicIndex.h +445 -0
  236. package/eigen/Eigen/src/Core/util/XprHelper.h +793 -538
  237. package/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h +246 -277
  238. package/eigen/Eigen/src/Eigenvalues/ComplexSchur.h +299 -319
  239. package/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +52 -48
  240. package/eigen/Eigen/src/Eigenvalues/EigenSolver.h +413 -456
  241. package/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +309 -325
  242. package/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +157 -171
  243. package/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h +292 -310
  244. package/eigen/Eigen/src/Eigenvalues/InternalHeaderCheck.h +3 -0
  245. package/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +91 -107
  246. package/eigen/Eigen/src/Eigenvalues/RealQZ.h +539 -606
  247. package/eigen/Eigen/src/Eigenvalues/RealSchur.h +348 -382
  248. package/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +41 -35
  249. package/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +579 -600
  250. package/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +47 -44
  251. package/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h +434 -461
  252. package/eigen/Eigen/src/Geometry/AlignedBox.h +307 -214
  253. package/eigen/Eigen/src/Geometry/AngleAxis.h +135 -137
  254. package/eigen/Eigen/src/Geometry/EulerAngles.h +163 -74
  255. package/eigen/Eigen/src/Geometry/Homogeneous.h +289 -333
  256. package/eigen/Eigen/src/Geometry/Hyperplane.h +152 -161
  257. package/eigen/Eigen/src/Geometry/InternalHeaderCheck.h +3 -0
  258. package/eigen/Eigen/src/Geometry/OrthoMethods.h +168 -145
  259. package/eigen/Eigen/src/Geometry/ParametrizedLine.h +141 -104
  260. package/eigen/Eigen/src/Geometry/Quaternion.h +595 -497
  261. package/eigen/Eigen/src/Geometry/Rotation2D.h +110 -108
  262. package/eigen/Eigen/src/Geometry/RotationBase.h +148 -145
  263. package/eigen/Eigen/src/Geometry/Scaling.h +115 -90
  264. package/eigen/Eigen/src/Geometry/Transform.h +896 -953
  265. package/eigen/Eigen/src/Geometry/Translation.h +100 -98
  266. package/eigen/Eigen/src/Geometry/Umeyama.h +79 -84
  267. package/eigen/Eigen/src/Geometry/arch/Geometry_SIMD.h +154 -0
  268. package/eigen/Eigen/src/Householder/BlockHouseholder.h +54 -42
  269. package/eigen/Eigen/src/Householder/Householder.h +104 -122
  270. package/eigen/Eigen/src/Householder/HouseholderSequence.h +416 -382
  271. package/eigen/Eigen/src/Householder/InternalHeaderCheck.h +3 -0
  272. package/eigen/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +153 -166
  273. package/eigen/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +127 -138
  274. package/eigen/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +95 -124
  275. package/eigen/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +269 -267
  276. package/eigen/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +246 -259
  277. package/eigen/Eigen/src/IterativeLinearSolvers/InternalHeaderCheck.h +3 -0
  278. package/eigen/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +218 -217
  279. package/eigen/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +80 -103
  280. package/eigen/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +59 -63
  281. package/eigen/Eigen/src/Jacobi/InternalHeaderCheck.h +3 -0
  282. package/eigen/Eigen/src/Jacobi/Jacobi.h +256 -291
  283. package/eigen/Eigen/src/KLUSupport/InternalHeaderCheck.h +3 -0
  284. package/eigen/Eigen/src/KLUSupport/KLUSupport.h +339 -0
  285. package/eigen/Eigen/src/LU/Determinant.h +60 -63
  286. package/eigen/Eigen/src/LU/FullPivLU.h +561 -626
  287. package/eigen/Eigen/src/LU/InternalHeaderCheck.h +3 -0
  288. package/eigen/Eigen/src/LU/InverseImpl.h +213 -275
  289. package/eigen/Eigen/src/LU/PartialPivLU.h +407 -435
  290. package/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h +54 -40
  291. package/eigen/Eigen/src/LU/arch/InverseSize4.h +353 -0
  292. package/eigen/Eigen/src/MetisSupport/InternalHeaderCheck.h +3 -0
  293. package/eigen/Eigen/src/MetisSupport/MetisSupport.h +81 -93
  294. package/eigen/Eigen/src/OrderingMethods/Amd.h +250 -282
  295. package/eigen/Eigen/src/OrderingMethods/Eigen_Colamd.h +950 -1103
  296. package/eigen/Eigen/src/OrderingMethods/InternalHeaderCheck.h +3 -0
  297. package/eigen/Eigen/src/OrderingMethods/Ordering.h +111 -122
  298. package/eigen/Eigen/src/PaStiXSupport/InternalHeaderCheck.h +3 -0
  299. package/eigen/Eigen/src/PaStiXSupport/PaStiXSupport.h +524 -570
  300. package/eigen/Eigen/src/PardisoSupport/InternalHeaderCheck.h +3 -0
  301. package/eigen/Eigen/src/PardisoSupport/PardisoSupport.h +385 -429
  302. package/eigen/Eigen/src/QR/ColPivHouseholderQR.h +494 -473
  303. package/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +120 -56
  304. package/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h +223 -137
  305. package/eigen/Eigen/src/QR/FullPivHouseholderQR.h +517 -460
  306. package/eigen/Eigen/src/QR/HouseholderQR.h +412 -278
  307. package/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h +32 -23
  308. package/eigen/Eigen/src/QR/InternalHeaderCheck.h +3 -0
  309. package/eigen/Eigen/src/SPQRSupport/InternalHeaderCheck.h +3 -0
  310. package/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +263 -261
  311. package/eigen/Eigen/src/SVD/BDCSVD.h +872 -679
  312. package/eigen/Eigen/src/SVD/BDCSVD_LAPACKE.h +174 -0
  313. package/eigen/Eigen/src/SVD/InternalHeaderCheck.h +3 -0
  314. package/eigen/Eigen/src/SVD/JacobiSVD.h +585 -543
  315. package/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h +85 -49
  316. package/eigen/Eigen/src/SVD/SVDBase.h +281 -160
  317. package/eigen/Eigen/src/SVD/UpperBidiagonalization.h +202 -237
  318. package/eigen/Eigen/src/SparseCholesky/InternalHeaderCheck.h +3 -0
  319. package/eigen/Eigen/src/SparseCholesky/SimplicialCholesky.h +769 -590
  320. package/eigen/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +318 -129
  321. package/eigen/Eigen/src/SparseCore/AmbiVector.h +202 -251
  322. package/eigen/Eigen/src/SparseCore/CompressedStorage.h +184 -236
  323. package/eigen/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +140 -184
  324. package/eigen/Eigen/src/SparseCore/InternalHeaderCheck.h +3 -0
  325. package/eigen/Eigen/src/SparseCore/SparseAssign.h +174 -111
  326. package/eigen/Eigen/src/SparseCore/SparseBlock.h +408 -477
  327. package/eigen/Eigen/src/SparseCore/SparseColEtree.h +100 -112
  328. package/eigen/Eigen/src/SparseCore/SparseCompressedBase.h +531 -280
  329. package/eigen/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +559 -347
  330. package/eigen/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +100 -108
  331. package/eigen/Eigen/src/SparseCore/SparseDenseProduct.h +185 -191
  332. package/eigen/Eigen/src/SparseCore/SparseDiagonalProduct.h +71 -71
  333. package/eigen/Eigen/src/SparseCore/SparseDot.h +49 -47
  334. package/eigen/Eigen/src/SparseCore/SparseFuzzy.h +13 -11
  335. package/eigen/Eigen/src/SparseCore/SparseMap.h +243 -253
  336. package/eigen/Eigen/src/SparseCore/SparseMatrix.h +1614 -1142
  337. package/eigen/Eigen/src/SparseCore/SparseMatrixBase.h +403 -357
  338. package/eigen/Eigen/src/SparseCore/SparsePermutation.h +186 -115
  339. package/eigen/Eigen/src/SparseCore/SparseProduct.h +100 -91
  340. package/eigen/Eigen/src/SparseCore/SparseRedux.h +22 -24
  341. package/eigen/Eigen/src/SparseCore/SparseRef.h +268 -295
  342. package/eigen/Eigen/src/SparseCore/SparseSelfAdjointView.h +371 -414
  343. package/eigen/Eigen/src/SparseCore/SparseSolverBase.h +78 -87
  344. package/eigen/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +81 -95
  345. package/eigen/Eigen/src/SparseCore/SparseTranspose.h +62 -71
  346. package/eigen/Eigen/src/SparseCore/SparseTriangularView.h +132 -144
  347. package/eigen/Eigen/src/SparseCore/SparseUtil.h +146 -115
  348. package/eigen/Eigen/src/SparseCore/SparseVector.h +426 -372
  349. package/eigen/Eigen/src/SparseCore/SparseView.h +164 -193
  350. package/eigen/Eigen/src/SparseCore/TriangularSolver.h +129 -170
  351. package/eigen/Eigen/src/SparseLU/InternalHeaderCheck.h +3 -0
  352. package/eigen/Eigen/src/SparseLU/SparseLU.h +814 -618
  353. package/eigen/Eigen/src/SparseLU/SparseLUImpl.h +61 -48
  354. package/eigen/Eigen/src/SparseLU/SparseLU_Memory.h +102 -118
  355. package/eigen/Eigen/src/SparseLU/SparseLU_Structs.h +38 -35
  356. package/eigen/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +273 -255
  357. package/eigen/Eigen/src/SparseLU/SparseLU_Utils.h +44 -49
  358. package/eigen/Eigen/src/SparseLU/SparseLU_column_bmod.h +104 -108
  359. package/eigen/Eigen/src/SparseLU/SparseLU_column_dfs.h +90 -101
  360. package/eigen/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +57 -58
  361. package/eigen/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +43 -55
  362. package/eigen/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +74 -71
  363. package/eigen/Eigen/src/SparseLU/SparseLU_panel_bmod.h +125 -133
  364. package/eigen/Eigen/src/SparseLU/SparseLU_panel_dfs.h +136 -159
  365. package/eigen/Eigen/src/SparseLU/SparseLU_pivotL.h +51 -52
  366. package/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h +67 -73
  367. package/eigen/Eigen/src/SparseLU/SparseLU_relax_snode.h +24 -26
  368. package/eigen/Eigen/src/SparseQR/InternalHeaderCheck.h +3 -0
  369. package/eigen/Eigen/src/SparseQR/SparseQR.h +451 -490
  370. package/eigen/Eigen/src/StlSupport/StdDeque.h +28 -105
  371. package/eigen/Eigen/src/StlSupport/StdList.h +28 -84
  372. package/eigen/Eigen/src/StlSupport/StdVector.h +28 -108
  373. package/eigen/Eigen/src/StlSupport/details.h +48 -50
  374. package/eigen/Eigen/src/SuperLUSupport/InternalHeaderCheck.h +3 -0
  375. package/eigen/Eigen/src/SuperLUSupport/SuperLUSupport.h +634 -732
  376. package/eigen/Eigen/src/ThreadPool/Barrier.h +70 -0
  377. package/eigen/Eigen/src/ThreadPool/CoreThreadPoolDevice.h +336 -0
  378. package/eigen/Eigen/src/ThreadPool/EventCount.h +241 -0
  379. package/eigen/Eigen/src/ThreadPool/ForkJoin.h +140 -0
  380. package/eigen/Eigen/src/ThreadPool/InternalHeaderCheck.h +4 -0
  381. package/eigen/Eigen/src/ThreadPool/NonBlockingThreadPool.h +587 -0
  382. package/eigen/Eigen/src/ThreadPool/RunQueue.h +230 -0
  383. package/eigen/Eigen/src/ThreadPool/ThreadCancel.h +21 -0
  384. package/eigen/Eigen/src/ThreadPool/ThreadEnvironment.h +43 -0
  385. package/eigen/Eigen/src/ThreadPool/ThreadLocal.h +289 -0
  386. package/eigen/Eigen/src/ThreadPool/ThreadPoolInterface.h +50 -0
  387. package/eigen/Eigen/src/ThreadPool/ThreadYield.h +16 -0
  388. package/eigen/Eigen/src/UmfPackSupport/InternalHeaderCheck.h +3 -0
  389. package/eigen/Eigen/src/UmfPackSupport/UmfPackSupport.h +480 -380
  390. package/eigen/Eigen/src/misc/Image.h +41 -43
  391. package/eigen/Eigen/src/misc/InternalHeaderCheck.h +3 -0
  392. package/eigen/Eigen/src/misc/Kernel.h +39 -41
  393. package/eigen/Eigen/src/misc/RealSvd2x2.h +19 -21
  394. package/eigen/Eigen/src/misc/blas.h +83 -426
  395. package/eigen/Eigen/src/misc/lapacke.h +9976 -16182
  396. package/eigen/Eigen/src/misc/lapacke_helpers.h +163 -0
  397. package/eigen/Eigen/src/misc/lapacke_mangling.h +4 -5
  398. package/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.inc +344 -0
  399. package/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.inc +544 -0
  400. package/eigen/Eigen/src/plugins/BlockMethods.inc +1370 -0
  401. package/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.inc +116 -0
  402. package/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.inc +167 -0
  403. package/eigen/Eigen/src/plugins/IndexedViewMethods.inc +192 -0
  404. package/eigen/Eigen/src/plugins/InternalHeaderCheck.inc +3 -0
  405. package/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.inc +331 -0
  406. package/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.inc +118 -0
  407. package/eigen/Eigen/src/plugins/ReshapedMethods.inc +133 -0
  408. package/lib/LibEigen.d.ts +4 -0
  409. package/lib/LibEigen.js +14 -0
  410. package/lib/index.d.ts +1 -1
  411. package/lib/index.js +7 -3
  412. package/package.json +2 -10
  413. package/eigen/Eigen/CMakeLists.txt +0 -19
  414. package/eigen/Eigen/src/Core/BooleanRedux.h +0 -164
  415. package/eigen/Eigen/src/Core/arch/CUDA/Complex.h +0 -103
  416. package/eigen/Eigen/src/Core/arch/CUDA/Half.h +0 -675
  417. package/eigen/Eigen/src/Core/arch/CUDA/MathFunctions.h +0 -91
  418. package/eigen/Eigen/src/Core/arch/CUDA/PacketMath.h +0 -333
  419. package/eigen/Eigen/src/Core/arch/CUDA/PacketMathHalf.h +0 -1124
  420. package/eigen/Eigen/src/Core/arch/CUDA/TypeCasting.h +0 -212
  421. package/eigen/Eigen/src/Core/util/NonMPL2.h +0 -3
  422. package/eigen/Eigen/src/Geometry/arch/Geometry_SSE.h +0 -161
  423. package/eigen/Eigen/src/LU/arch/Inverse_SSE.h +0 -338
  424. package/eigen/Eigen/src/SparseCore/MappedSparseMatrix.h +0 -67
  425. package/eigen/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +0 -280
  426. package/eigen/Eigen/src/misc/lapack.h +0 -152
  427. package/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +0 -332
  428. package/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +0 -552
  429. package/eigen/Eigen/src/plugins/BlockMethods.h +0 -1058
  430. package/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +0 -115
  431. package/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +0 -163
  432. package/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +0 -152
  433. package/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +0 -85
  434. package/lib/eigen.d.ts +0 -2
  435. package/lib/eigen.js +0 -15
@@ -10,44 +10,47 @@
10
10
  #ifndef EIGEN_SPARSEMATRIX_H
11
11
  #define EIGEN_SPARSEMATRIX_H
12
12
 
13
- namespace Eigen {
13
+ // IWYU pragma: private
14
+ #include "./InternalHeaderCheck.h"
15
+
16
+ namespace Eigen {
14
17
 
15
18
  /** \ingroup SparseCore_Module
16
- *
17
- * \class SparseMatrix
18
- *
19
- * \brief A versatible sparse matrix representation
20
- *
21
- * This class implements a more versatile variants of the common \em compressed row/column storage format.
22
- * Each colmun's (resp. row) non zeros are stored as a pair of value with associated row (resp. colmiun) index.
23
- * All the non zeros are stored in a single large buffer. Unlike the \em compressed format, there might be extra
24
- * space inbetween the nonzeros of two successive colmuns (resp. rows) such that insertion of new non-zero
25
- * can be done with limited memory reallocation and copies.
26
- *
27
- * A call to the function makeCompressed() turns the matrix into the standard \em compressed format
28
- * compatible with many library.
29
- *
30
- * More details on this storage sceheme are given in the \ref TutorialSparse "manual pages".
31
- *
32
- * \tparam _Scalar the scalar type, i.e. the type of the coefficients
33
- * \tparam _Options Union of bit flags controlling the storage scheme. Currently the only possibility
34
- * is ColMajor or RowMajor. The default is 0 which means column-major.
35
- * \tparam _StorageIndex the type of the indices. It has to be a \b signed type (e.g., short, int, std::ptrdiff_t). Default is \c int.
36
- *
37
- * \warning In %Eigen 3.2, the undocumented type \c SparseMatrix::Index was improperly defined as the storage index type (e.g., int),
38
- * whereas it is now (starting from %Eigen 3.3) deprecated and always defined as Eigen::Index.
39
- * Codes making use of \c SparseMatrix::Index, might thus likely have to be changed to use \c SparseMatrix::StorageIndex instead.
40
- *
41
- * This class can be extended with the help of the plugin mechanism described on the page
42
- * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEMATRIX_PLUGIN.
43
- */
19
+ *
20
+ * \class SparseMatrix
21
+ *
22
+ * \brief A versatible sparse matrix representation
23
+ *
24
+ * This class implements a more versatile variants of the common \em compressed row/column storage format.
25
+ * Each colmun's (resp. row) non zeros are stored as a pair of value with associated row (resp. colmiun) index.
26
+ * All the non zeros are stored in a single large buffer. Unlike the \em compressed format, there might be extra
27
+ * space in between the nonzeros of two successive colmuns (resp. rows) such that insertion of new non-zero
28
+ * can be done with limited memory reallocation and copies.
29
+ *
30
+ * A call to the function makeCompressed() turns the matrix into the standard \em compressed format
31
+ * compatible with many library.
32
+ *
33
+ * More details on this storage sceheme are given in the \ref TutorialSparse "manual pages".
34
+ *
35
+ * \tparam Scalar_ the scalar type, i.e. the type of the coefficients
36
+ * \tparam Options_ Union of bit flags controlling the storage scheme. Currently the only possibility
37
+ * is ColMajor or RowMajor. The default is 0 which means column-major.
38
+ * \tparam StorageIndex_ the type of the indices. It has to be a \b signed type (e.g., short, int, std::ptrdiff_t).
39
+ * Default is \c int.
40
+ *
41
+ * \warning In %Eigen 3.2, the undocumented type \c SparseMatrix::Index was improperly defined as the storage index type
42
+ * (e.g., int), whereas it is now (starting from %Eigen 3.3) deprecated and always defined as Eigen::Index. Codes making
43
+ * use of \c SparseMatrix::Index, might thus likely have to be changed to use \c SparseMatrix::StorageIndex instead.
44
+ *
45
+ * This class can be extended with the help of the plugin mechanism described on the page
46
+ * \ref TopicCustomizing_Plugins by defining the preprocessor symbol \c EIGEN_SPARSEMATRIX_PLUGIN.
47
+ */
44
48
 
45
49
  namespace internal {
46
- template<typename _Scalar, int _Options, typename _StorageIndex>
47
- struct traits<SparseMatrix<_Scalar, _Options, _StorageIndex> >
48
- {
49
- typedef _Scalar Scalar;
50
- typedef _StorageIndex StorageIndex;
50
+ template <typename Scalar_, int Options_, typename StorageIndex_>
51
+ struct traits<SparseMatrix<Scalar_, Options_, StorageIndex_>> {
52
+ typedef Scalar_ Scalar;
53
+ typedef StorageIndex_ StorageIndex;
51
54
  typedef Sparse StorageKind;
52
55
  typedef MatrixXpr XprKind;
53
56
  enum {
@@ -55,21 +58,21 @@ struct traits<SparseMatrix<_Scalar, _Options, _StorageIndex> >
55
58
  ColsAtCompileTime = Dynamic,
56
59
  MaxRowsAtCompileTime = Dynamic,
57
60
  MaxColsAtCompileTime = Dynamic,
58
- Flags = _Options | NestByRefBit | LvalueBit | CompressedAccessBit,
61
+ Options = Options_,
62
+ Flags = Options_ | NestByRefBit | LvalueBit | CompressedAccessBit,
59
63
  SupportedAccessPatterns = InnerRandomAccessPattern
60
64
  };
61
65
  };
62
66
 
63
- template<typename _Scalar, int _Options, typename _StorageIndex, int DiagIndex>
64
- struct traits<Diagonal<SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> >
65
- {
66
- typedef SparseMatrix<_Scalar, _Options, _StorageIndex> MatrixType;
67
+ template <typename Scalar_, int Options_, typename StorageIndex_, int DiagIndex>
68
+ struct traits<Diagonal<SparseMatrix<Scalar_, Options_, StorageIndex_>, DiagIndex>> {
69
+ typedef SparseMatrix<Scalar_, Options_, StorageIndex_> MatrixType;
67
70
  typedef typename ref_selector<MatrixType>::type MatrixTypeNested;
68
- typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
71
+ typedef std::remove_reference_t<MatrixTypeNested> MatrixTypeNested_;
69
72
 
70
- typedef _Scalar Scalar;
73
+ typedef Scalar_ Scalar;
71
74
  typedef Dense StorageKind;
72
- typedef _StorageIndex StorageIndex;
75
+ typedef StorageIndex_ StorageIndex;
73
76
  typedef MatrixXpr XprKind;
74
77
 
75
78
  enum {
@@ -81,833 +84,1032 @@ struct traits<Diagonal<SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex
81
84
  };
82
85
  };
83
86
 
84
- template<typename _Scalar, int _Options, typename _StorageIndex, int DiagIndex>
85
- struct traits<Diagonal<const SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> >
86
- : public traits<Diagonal<SparseMatrix<_Scalar, _Options, _StorageIndex>, DiagIndex> >
87
- {
88
- enum {
89
- Flags = 0
90
- };
87
+ template <typename Scalar_, int Options_, typename StorageIndex_, int DiagIndex>
88
+ struct traits<Diagonal<const SparseMatrix<Scalar_, Options_, StorageIndex_>, DiagIndex>>
89
+ : public traits<Diagonal<SparseMatrix<Scalar_, Options_, StorageIndex_>, DiagIndex>> {
90
+ enum { Flags = 0 };
91
91
  };
92
92
 
93
- } // end namespace internal
94
-
95
- template<typename _Scalar, int _Options, typename _StorageIndex>
96
- class SparseMatrix
97
- : public SparseCompressedBase<SparseMatrix<_Scalar, _Options, _StorageIndex> >
98
- {
99
- typedef SparseCompressedBase<SparseMatrix> Base;
100
- using Base::convert_index;
101
- friend class SparseVector<_Scalar,0,_StorageIndex>;
102
- public:
103
- using Base::isCompressed;
104
- using Base::nonZeros;
105
- EIGEN_SPARSE_PUBLIC_INTERFACE(SparseMatrix)
106
- using Base::operator+=;
107
- using Base::operator-=;
108
-
109
- typedef MappedSparseMatrix<Scalar,Flags> Map;
110
- typedef Diagonal<SparseMatrix> DiagonalReturnType;
111
- typedef Diagonal<const SparseMatrix> ConstDiagonalReturnType;
112
- typedef typename Base::InnerIterator InnerIterator;
113
- typedef typename Base::ReverseInnerIterator ReverseInnerIterator;
114
-
115
-
116
- using Base::IsRowMajor;
117
- typedef internal::CompressedStorage<Scalar,StorageIndex> Storage;
118
- enum {
119
- Options = _Options
120
- };
121
-
122
- typedef typename Base::IndexVector IndexVector;
123
- typedef typename Base::ScalarVector ScalarVector;
124
- protected:
125
- typedef SparseMatrix<Scalar,(Flags&~RowMajorBit)|(IsRowMajor?RowMajorBit:0)> TransposedSparseMatrix;
126
-
127
- Index m_outerSize;
128
- Index m_innerSize;
129
- StorageIndex* m_outerIndex;
130
- StorageIndex* m_innerNonZeros; // optional, if null then the data is compressed
131
- Storage m_data;
132
-
133
- public:
134
-
135
- /** \returns the number of rows of the matrix */
136
- inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; }
137
- /** \returns the number of columns of the matrix */
138
- inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; }
139
-
140
- /** \returns the number of rows (resp. columns) of the matrix if the storage order column major (resp. row major) */
141
- inline Index innerSize() const { return m_innerSize; }
142
- /** \returns the number of columns (resp. rows) of the matrix if the storage order column major (resp. row major) */
143
- inline Index outerSize() const { return m_outerSize; }
144
-
145
- /** \returns a const pointer to the array of values.
146
- * This function is aimed at interoperability with other libraries.
147
- * \sa innerIndexPtr(), outerIndexPtr() */
148
- inline const Scalar* valuePtr() const { return m_data.valuePtr(); }
149
- /** \returns a non-const pointer to the array of values.
150
- * This function is aimed at interoperability with other libraries.
151
- * \sa innerIndexPtr(), outerIndexPtr() */
152
- inline Scalar* valuePtr() { return m_data.valuePtr(); }
153
-
154
- /** \returns a const pointer to the array of inner indices.
155
- * This function is aimed at interoperability with other libraries.
156
- * \sa valuePtr(), outerIndexPtr() */
157
- inline const StorageIndex* innerIndexPtr() const { return m_data.indexPtr(); }
158
- /** \returns a non-const pointer to the array of inner indices.
159
- * This function is aimed at interoperability with other libraries.
160
- * \sa valuePtr(), outerIndexPtr() */
161
- inline StorageIndex* innerIndexPtr() { return m_data.indexPtr(); }
162
-
163
- /** \returns a const pointer to the array of the starting positions of the inner vectors.
164
- * This function is aimed at interoperability with other libraries.
165
- * \sa valuePtr(), innerIndexPtr() */
166
- inline const StorageIndex* outerIndexPtr() const { return m_outerIndex; }
167
- /** \returns a non-const pointer to the array of the starting positions of the inner vectors.
168
- * This function is aimed at interoperability with other libraries.
169
- * \sa valuePtr(), innerIndexPtr() */
170
- inline StorageIndex* outerIndexPtr() { return m_outerIndex; }
171
-
172
- /** \returns a const pointer to the array of the number of non zeros of the inner vectors.
173
- * This function is aimed at interoperability with other libraries.
174
- * \warning it returns the null pointer 0 in compressed mode */
175
- inline const StorageIndex* innerNonZeroPtr() const { return m_innerNonZeros; }
176
- /** \returns a non-const pointer to the array of the number of non zeros of the inner vectors.
177
- * This function is aimed at interoperability with other libraries.
178
- * \warning it returns the null pointer 0 in compressed mode */
179
- inline StorageIndex* innerNonZeroPtr() { return m_innerNonZeros; }
180
-
181
- /** \internal */
182
- inline Storage& data() { return m_data; }
183
- /** \internal */
184
- inline const Storage& data() const { return m_data; }
185
-
186
- /** \returns the value of the matrix at position \a i, \a j
187
- * This function returns Scalar(0) if the element is an explicit \em zero */
188
- inline Scalar coeff(Index row, Index col) const
189
- {
190
- eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
191
-
192
- const Index outer = IsRowMajor ? row : col;
193
- const Index inner = IsRowMajor ? col : row;
194
- Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1];
195
- return m_data.atInRange(m_outerIndex[outer], end, StorageIndex(inner));
196
- }
93
+ template <typename StorageIndex>
94
+ struct sparse_reserve_op {
95
+ EIGEN_DEVICE_FUNC sparse_reserve_op(Index begin, Index end, Index size) {
96
+ Index range = numext::mini(end - begin, size);
97
+ m_begin = begin;
98
+ m_end = begin + range;
99
+ m_val = StorageIndex(size / range);
100
+ m_remainder = StorageIndex(size % range);
101
+ }
102
+ template <typename IndexType>
103
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex operator()(IndexType i) const {
104
+ if ((i >= m_begin) && (i < m_end))
105
+ return m_val + ((i - m_begin) < m_remainder ? 1 : 0);
106
+ else
107
+ return 0;
108
+ }
109
+ StorageIndex m_val, m_remainder;
110
+ Index m_begin, m_end;
111
+ };
197
112
 
198
- /** \returns a non-const reference to the value of the matrix at position \a i, \a j
199
- *
200
- * If the element does not exist then it is inserted via the insert(Index,Index) function
201
- * which itself turns the matrix into a non compressed form if that was not the case.
202
- *
203
- * This is a O(log(nnz_j)) operation (binary search) plus the cost of insert(Index,Index)
204
- * function if the element does not already exist.
205
- */
206
- inline Scalar& coeffRef(Index row, Index col)
207
- {
208
- eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
209
-
210
- const Index outer = IsRowMajor ? row : col;
211
- const Index inner = IsRowMajor ? col : row;
212
-
213
- Index start = m_outerIndex[outer];
214
- Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer+1];
215
- eigen_assert(end>=start && "you probably called coeffRef on a non finalized matrix");
216
- if(end<=start)
217
- return insert(row,col);
218
- const Index p = m_data.searchLowerIndex(start,end-1,StorageIndex(inner));
219
- if((p<end) && (m_data.index(p)==inner))
220
- return m_data.value(p);
221
- else
222
- return insert(row,col);
223
- }
113
+ template <typename Scalar>
114
+ struct functor_traits<sparse_reserve_op<Scalar>> {
115
+ enum { Cost = 1, PacketAccess = false, IsRepeatable = true };
116
+ };
224
117
 
225
- /** \returns a reference to a novel non zero coefficient with coordinates \a row x \a col.
226
- * The non zero coefficient must \b not already exist.
227
- *
228
- * If the matrix \c *this is in compressed mode, then \c *this is turned into uncompressed
229
- * mode while reserving room for 2 x this->innerSize() non zeros if reserve(Index) has not been called earlier.
230
- * In this case, the insertion procedure is optimized for a \e sequential insertion mode where elements are assumed to be
231
- * inserted by increasing outer-indices.
232
- *
233
- * If that's not the case, then it is strongly recommended to either use a triplet-list to assemble the matrix, or to first
234
- * call reserve(const SizesType &) to reserve the appropriate number of non-zero elements per inner vector.
235
- *
236
- * Assuming memory has been appropriately reserved, this function performs a sorted insertion in O(1)
237
- * if the elements of each inner vector are inserted in increasing inner index order, and in O(nnz_j) for a random insertion.
238
- *
239
- */
240
- Scalar& insert(Index row, Index col);
241
-
242
- public:
243
-
244
- /** Removes all non zeros but keep allocated memory
245
- *
246
- * This function does not free the currently allocated memory. To release as much as memory as possible,
247
- * call \code mat.data().squeeze(); \endcode after resizing it.
248
- *
249
- * \sa resize(Index,Index), data()
250
- */
251
- inline void setZero()
252
- {
253
- m_data.clear();
254
- memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(StorageIndex));
255
- if(m_innerNonZeros)
256
- memset(m_innerNonZeros, 0, (m_outerSize)*sizeof(StorageIndex));
257
- }
118
+ } // end namespace internal
119
+
120
+ template <typename Scalar_, int Options_, typename StorageIndex_>
121
+ class SparseMatrix : public SparseCompressedBase<SparseMatrix<Scalar_, Options_, StorageIndex_>> {
122
+ typedef SparseCompressedBase<SparseMatrix> Base;
123
+ using Base::convert_index;
124
+ friend class SparseVector<Scalar_, 0, StorageIndex_>;
125
+ template <typename, typename, typename, typename, typename>
126
+ friend struct internal::Assignment;
127
+
128
+ public:
129
+ using Base::isCompressed;
130
+ using Base::nonZeros;
131
+ EIGEN_SPARSE_PUBLIC_INTERFACE(SparseMatrix)
132
+ using Base::operator+=;
133
+ using Base::operator-=;
134
+
135
+ typedef Eigen::Map<SparseMatrix<Scalar, Options_, StorageIndex>> Map;
136
+ typedef Diagonal<SparseMatrix> DiagonalReturnType;
137
+ typedef Diagonal<const SparseMatrix> ConstDiagonalReturnType;
138
+ typedef typename Base::InnerIterator InnerIterator;
139
+ typedef typename Base::ReverseInnerIterator ReverseInnerIterator;
140
+
141
+ using Base::IsRowMajor;
142
+ typedef internal::CompressedStorage<Scalar, StorageIndex> Storage;
143
+ enum { Options = Options_ };
144
+
145
+ typedef typename Base::IndexVector IndexVector;
146
+ typedef typename Base::ScalarVector ScalarVector;
147
+
148
+ protected:
149
+ typedef SparseMatrix<Scalar, IsRowMajor ? ColMajor : RowMajor, StorageIndex> TransposedSparseMatrix;
150
+
151
+ Index m_outerSize;
152
+ Index m_innerSize;
153
+ StorageIndex* m_outerIndex;
154
+ StorageIndex* m_innerNonZeros; // optional, if null then the data is compressed
155
+ Storage m_data;
156
+
157
+ public:
158
+ /** \returns the number of rows of the matrix */
159
+ inline Index rows() const { return IsRowMajor ? m_outerSize : m_innerSize; }
160
+ /** \returns the number of columns of the matrix */
161
+ inline Index cols() const { return IsRowMajor ? m_innerSize : m_outerSize; }
162
+
163
+ /** \returns the number of rows (resp. columns) of the matrix if the storage order column major (resp. row major) */
164
+ inline Index innerSize() const { return m_innerSize; }
165
+ /** \returns the number of columns (resp. rows) of the matrix if the storage order column major (resp. row major) */
166
+ inline Index outerSize() const { return m_outerSize; }
167
+
168
+ /** \returns a const pointer to the array of values.
169
+ * This function is aimed at interoperability with other libraries.
170
+ * \sa innerIndexPtr(), outerIndexPtr() */
171
+ inline const Scalar* valuePtr() const { return m_data.valuePtr(); }
172
+ /** \returns a non-const pointer to the array of values.
173
+ * This function is aimed at interoperability with other libraries.
174
+ * \sa innerIndexPtr(), outerIndexPtr() */
175
+ inline Scalar* valuePtr() { return m_data.valuePtr(); }
176
+
177
+ /** \returns a const pointer to the array of inner indices.
178
+ * This function is aimed at interoperability with other libraries.
179
+ * \sa valuePtr(), outerIndexPtr() */
180
+ inline const StorageIndex* innerIndexPtr() const { return m_data.indexPtr(); }
181
+ /** \returns a non-const pointer to the array of inner indices.
182
+ * This function is aimed at interoperability with other libraries.
183
+ * \sa valuePtr(), outerIndexPtr() */
184
+ inline StorageIndex* innerIndexPtr() { return m_data.indexPtr(); }
185
+
186
+ /** \returns a const pointer to the array of the starting positions of the inner vectors.
187
+ * This function is aimed at interoperability with other libraries.
188
+ * \sa valuePtr(), innerIndexPtr() */
189
+ inline const StorageIndex* outerIndexPtr() const { return m_outerIndex; }
190
+ /** \returns a non-const pointer to the array of the starting positions of the inner vectors.
191
+ * This function is aimed at interoperability with other libraries.
192
+ * \sa valuePtr(), innerIndexPtr() */
193
+ inline StorageIndex* outerIndexPtr() { return m_outerIndex; }
194
+
195
+ /** \returns a const pointer to the array of the number of non zeros of the inner vectors.
196
+ * This function is aimed at interoperability with other libraries.
197
+ * \warning it returns the null pointer 0 in compressed mode */
198
+ inline const StorageIndex* innerNonZeroPtr() const { return m_innerNonZeros; }
199
+ /** \returns a non-const pointer to the array of the number of non zeros of the inner vectors.
200
+ * This function is aimed at interoperability with other libraries.
201
+ * \warning it returns the null pointer 0 in compressed mode */
202
+ inline StorageIndex* innerNonZeroPtr() { return m_innerNonZeros; }
203
+
204
+ /** \internal */
205
+ constexpr Storage& data() { return m_data; }
206
+ /** \internal */
207
+ constexpr const Storage& data() const { return m_data; }
208
+
209
+ /** \returns the value of the matrix at position \a i, \a j
210
+ * This function returns Scalar(0) if the element is an explicit \em zero */
211
+ inline Scalar coeff(Index row, Index col) const {
212
+ eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
213
+
214
+ const Index outer = IsRowMajor ? row : col;
215
+ const Index inner = IsRowMajor ? col : row;
216
+ Index end = m_innerNonZeros ? m_outerIndex[outer] + m_innerNonZeros[outer] : m_outerIndex[outer + 1];
217
+ return m_data.atInRange(m_outerIndex[outer], end, inner);
218
+ }
258
219
 
259
- /** Preallocates \a reserveSize non zeros.
260
- *
261
- * Precondition: the matrix must be in compressed mode. */
262
- inline void reserve(Index reserveSize)
263
- {
264
- eigen_assert(isCompressed() && "This function does not make sense in non compressed mode.");
265
- m_data.reserve(reserveSize);
266
- }
267
-
268
- #ifdef EIGEN_PARSED_BY_DOXYGEN
269
- /** Preallocates \a reserveSize[\c j] non zeros for each column (resp. row) \c j.
270
- *
271
- * This function turns the matrix in non-compressed mode.
272
- *
273
- * The type \c SizesType must expose the following interface:
274
- \code
275
- typedef value_type;
276
- const value_type& operator[](i) const;
277
- \endcode
278
- * for \c i in the [0,this->outerSize()[ range.
279
- * Typical choices include std::vector<int>, Eigen::VectorXi, Eigen::VectorXi::Constant, etc.
280
- */
281
- template<class SizesType>
282
- inline void reserve(const SizesType& reserveSizes);
283
- #else
284
- template<class SizesType>
285
- inline void reserve(const SizesType& reserveSizes, const typename SizesType::value_type& enableif =
286
- #if (!EIGEN_COMP_MSVC) || (EIGEN_COMP_MSVC>=1500) // MSVC 2005 fails to compile with this typename
287
- typename
288
- #endif
289
- SizesType::value_type())
290
- {
291
- EIGEN_UNUSED_VARIABLE(enableif);
292
- reserveInnerVectors(reserveSizes);
293
- }
294
- #endif // EIGEN_PARSED_BY_DOXYGEN
295
- protected:
296
- template<class SizesType>
297
- inline void reserveInnerVectors(const SizesType& reserveSizes)
298
- {
299
- if(isCompressed())
300
- {
301
- Index totalReserveSize = 0;
302
- // turn the matrix into non-compressed mode
303
- m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex)));
304
- if (!m_innerNonZeros) internal::throw_std_bad_alloc();
305
-
306
- // temporarily use m_innerSizes to hold the new starting points.
307
- StorageIndex* newOuterIndex = m_innerNonZeros;
308
-
309
- StorageIndex count = 0;
310
- for(Index j=0; j<m_outerSize; ++j)
311
- {
312
- newOuterIndex[j] = count;
313
- count += reserveSizes[j] + (m_outerIndex[j+1]-m_outerIndex[j]);
314
- totalReserveSize += reserveSizes[j];
315
- }
316
- m_data.reserve(totalReserveSize);
317
- StorageIndex previousOuterIndex = m_outerIndex[m_outerSize];
318
- for(Index j=m_outerSize-1; j>=0; --j)
319
- {
320
- StorageIndex innerNNZ = previousOuterIndex - m_outerIndex[j];
321
- for(Index i=innerNNZ-1; i>=0; --i)
322
- {
323
- m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i);
324
- m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i);
325
- }
326
- previousOuterIndex = m_outerIndex[j];
327
- m_outerIndex[j] = newOuterIndex[j];
328
- m_innerNonZeros[j] = innerNNZ;
329
- }
330
- if(m_outerSize>0)
331
- m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize-1] + m_innerNonZeros[m_outerSize-1] + reserveSizes[m_outerSize-1];
332
-
333
- m_data.resize(m_outerIndex[m_outerSize]);
334
- }
335
- else
336
- {
337
- StorageIndex* newOuterIndex = static_cast<StorageIndex*>(std::malloc((m_outerSize+1)*sizeof(StorageIndex)));
338
- if (!newOuterIndex) internal::throw_std_bad_alloc();
339
-
340
- StorageIndex count = 0;
341
- for(Index j=0; j<m_outerSize; ++j)
342
- {
343
- newOuterIndex[j] = count;
344
- StorageIndex alreadyReserved = (m_outerIndex[j+1]-m_outerIndex[j]) - m_innerNonZeros[j];
345
- StorageIndex toReserve = std::max<StorageIndex>(reserveSizes[j], alreadyReserved);
346
- count += toReserve + m_innerNonZeros[j];
347
- }
348
- newOuterIndex[m_outerSize] = count;
349
-
350
- m_data.resize(count);
351
- for(Index j=m_outerSize-1; j>=0; --j)
352
- {
353
- Index offset = newOuterIndex[j] - m_outerIndex[j];
354
- if(offset>0)
355
- {
356
- StorageIndex innerNNZ = m_innerNonZeros[j];
357
- for(Index i=innerNNZ-1; i>=0; --i)
358
- {
359
- m_data.index(newOuterIndex[j]+i) = m_data.index(m_outerIndex[j]+i);
360
- m_data.value(newOuterIndex[j]+i) = m_data.value(m_outerIndex[j]+i);
361
- }
362
- }
220
+ /** \returns a non-const reference to the value of the matrix at position \a i, \a j.
221
+ *
222
+ * If the element does not exist then it is inserted via the insert(Index,Index) function
223
+ * which itself turns the matrix into a non compressed form if that was not the case.
224
+ * The output parameter `inserted` is set to true.
225
+ *
226
+ * Otherwise, if the element does exist, `inserted` will be set to false.
227
+ *
228
+ * This is a O(log(nnz_j)) operation (binary search) plus the cost of insert(Index,Index)
229
+ * function if the element does not already exist.
230
+ */
231
+ inline Scalar& findOrInsertCoeff(Index row, Index col, bool* inserted) {
232
+ eigen_assert(row >= 0 && row < rows() && col >= 0 && col < cols());
233
+ const Index outer = IsRowMajor ? row : col;
234
+ const Index inner = IsRowMajor ? col : row;
235
+ Index start = m_outerIndex[outer];
236
+ Index end = isCompressed() ? m_outerIndex[outer + 1] : m_outerIndex[outer] + m_innerNonZeros[outer];
237
+ eigen_assert(end >= start && "you probably called coeffRef on a non finalized matrix");
238
+ Index dst = start == end ? end : m_data.searchLowerIndex(start, end, inner);
239
+ if (dst == end) {
240
+ Index capacity = m_outerIndex[outer + 1] - end;
241
+ if (capacity > 0) {
242
+ // implies uncompressed: push to back of vector
243
+ m_innerNonZeros[outer]++;
244
+ m_data.index(end) = StorageIndex(inner);
245
+ m_data.value(end) = Scalar(0);
246
+ if (inserted != nullptr) {
247
+ *inserted = true;
363
248
  }
364
-
365
- std::swap(m_outerIndex, newOuterIndex);
366
- std::free(newOuterIndex);
249
+ return m_data.value(end);
367
250
  }
368
-
369
251
  }
370
- public:
371
-
372
- //--- low level purely coherent filling ---
373
-
374
- /** \internal
375
- * \returns a reference to the non zero coefficient at position \a row, \a col assuming that:
376
- * - the nonzero does not already exist
377
- * - the new coefficient is the last one according to the storage order
378
- *
379
- * Before filling a given inner vector you must call the statVec(Index) function.
380
- *
381
- * After an insertion session, you should call the finalize() function.
382
- *
383
- * \sa insert, insertBackByOuterInner, startVec */
384
- inline Scalar& insertBack(Index row, Index col)
385
- {
386
- return insertBackByOuterInner(IsRowMajor?row:col, IsRowMajor?col:row);
252
+ if ((dst < end) && (m_data.index(dst) == inner)) {
253
+ // this coefficient exists, return a reference to it
254
+ if (inserted != nullptr) {
255
+ *inserted = false;
256
+ }
257
+ return m_data.value(dst);
258
+ } else {
259
+ if (inserted != nullptr) {
260
+ *inserted = true;
261
+ }
262
+ // insertion will require reconfiguring the buffer
263
+ return insertAtByOuterInner(outer, inner, dst);
387
264
  }
265
+ }
388
266
 
389
- /** \internal
390
- * \sa insertBack, startVec */
391
- inline Scalar& insertBackByOuterInner(Index outer, Index inner)
392
- {
393
- eigen_assert(Index(m_outerIndex[outer+1]) == m_data.size() && "Invalid ordered insertion (invalid outer index)");
394
- eigen_assert( (m_outerIndex[outer+1]-m_outerIndex[outer]==0 || m_data.index(m_data.size()-1)<inner) && "Invalid ordered insertion (invalid inner index)");
395
- Index p = m_outerIndex[outer+1];
396
- ++m_outerIndex[outer+1];
397
- m_data.append(Scalar(0), inner);
398
- return m_data.value(p);
267
+ /** \returns a non-const reference to the value of the matrix at position \a i, \a j
268
+ *
269
+ * If the element does not exist then it is inserted via the insert(Index,Index) function
270
+ * which itself turns the matrix into a non compressed form if that was not the case.
271
+ *
272
+ * This is a O(log(nnz_j)) operation (binary search) plus the cost of insert(Index,Index)
273
+ * function if the element does not already exist.
274
+ */
275
+ inline Scalar& coeffRef(Index row, Index col) { return findOrInsertCoeff(row, col, nullptr); }
276
+
277
+ /** \returns a reference to a novel non zero coefficient with coordinates \a row x \a col.
278
+ * The non zero coefficient must \b not already exist.
279
+ *
280
+ * If the matrix \c *this is in compressed mode, then \c *this is turned into uncompressed
281
+ * mode while reserving room for 2 x this->innerSize() non zeros if reserve(Index) has not been called earlier.
282
+ * In this case, the insertion procedure is optimized for a \e sequential insertion mode where elements are assumed to
283
+ * be inserted by increasing outer-indices.
284
+ *
285
+ * If that's not the case, then it is strongly recommended to either use a triplet-list to assemble the matrix, or to
286
+ * first call reserve(const SizesType &) to reserve the appropriate number of non-zero elements per inner vector.
287
+ *
288
+ * Assuming memory has been appropriately reserved, this function performs a sorted insertion in O(1)
289
+ * if the elements of each inner vector are inserted in increasing inner index order, and in O(nnz_j) for a random
290
+ * insertion.
291
+ *
292
+ */
293
+ inline Scalar& insert(Index row, Index col);
294
+
295
+ public:
296
+ /** Removes all non zeros but keep allocated memory
297
+ *
298
+ * This function does not free the currently allocated memory. To release as much as memory as possible,
299
+ * call \code mat.data().squeeze(); \endcode after resizing it.
300
+ *
301
+ * \sa resize(Index,Index), data()
302
+ */
303
+ inline void setZero() {
304
+ m_data.clear();
305
+ using std::fill_n;
306
+ fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0));
307
+ if (m_innerNonZeros) {
308
+ fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0));
399
309
  }
310
+ }
400
311
 
401
- /** \internal
402
- * \warning use it only if you know what you are doing */
403
- inline Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner)
404
- {
405
- Index p = m_outerIndex[outer+1];
406
- ++m_outerIndex[outer+1];
407
- m_data.append(Scalar(0), inner);
408
- return m_data.value(p);
409
- }
312
+ /** Preallocates \a reserveSize non zeros.
313
+ *
314
+ * Precondition: the matrix must be in compressed mode. */
315
+ inline void reserve(Index reserveSize) {
316
+ eigen_assert(isCompressed() && "This function does not make sense in non compressed mode.");
317
+ m_data.reserve(reserveSize);
318
+ }
410
319
 
411
- /** \internal
412
- * \sa insertBack, insertBackByOuterInner */
413
- inline void startVec(Index outer)
414
- {
415
- eigen_assert(m_outerIndex[outer]==Index(m_data.size()) && "You must call startVec for each inner vector sequentially");
416
- eigen_assert(m_outerIndex[outer+1]==0 && "You must call startVec for each inner vector sequentially");
417
- m_outerIndex[outer+1] = m_outerIndex[outer];
320
+ #ifdef EIGEN_PARSED_BY_DOXYGEN
321
+ /** Preallocates \a reserveSize[\c j] non zeros for each column (resp. row) \c j.
322
+ *
323
+ * This function turns the matrix in non-compressed mode.
324
+ *
325
+ * The type \c SizesType must expose the following interface:
326
+ \code
327
+ typedef value_type;
328
+ const value_type& operator[](i) const;
329
+ \endcode
330
+ * for \c i in the [0,this->outerSize()[ range.
331
+ * Typical choices include std::vector<int>, Eigen::VectorXi, Eigen::VectorXi::Constant, etc.
332
+ */
333
+ template <class SizesType>
334
+ inline void reserve(const SizesType& reserveSizes);
335
+ #else
336
+ template <class SizesType>
337
+ inline void reserve(const SizesType& reserveSizes,
338
+ const typename SizesType::value_type& enableif = typename SizesType::value_type()) {
339
+ EIGEN_UNUSED_VARIABLE(enableif);
340
+ reserveInnerVectors(reserveSizes);
341
+ }
342
+ #endif // EIGEN_PARSED_BY_DOXYGEN
343
+ protected:
344
+ template <class SizesType>
345
+ inline void reserveInnerVectors(const SizesType& reserveSizes) {
346
+ if (isCompressed()) {
347
+ Index totalReserveSize = 0;
348
+ for (Index j = 0; j < m_outerSize; ++j) totalReserveSize += internal::convert_index<Index>(reserveSizes[j]);
349
+
350
+ // if reserveSizes is empty, don't do anything!
351
+ if (totalReserveSize == 0) return;
352
+
353
+ // turn the matrix into non-compressed mode
354
+ m_innerNonZeros = internal::conditional_aligned_new_auto<StorageIndex, true>(m_outerSize);
355
+
356
+ // temporarily use m_innerSizes to hold the new starting points.
357
+ StorageIndex* newOuterIndex = m_innerNonZeros;
358
+
359
+ Index count = 0;
360
+ for (Index j = 0; j < m_outerSize; ++j) {
361
+ newOuterIndex[j] = internal::convert_index<StorageIndex>(count);
362
+ Index reserveSize = internal::convert_index<Index>(reserveSizes[j]);
363
+ count += reserveSize + internal::convert_index<Index>(m_outerIndex[j + 1] - m_outerIndex[j]);
364
+ }
365
+
366
+ m_data.reserve(totalReserveSize);
367
+ StorageIndex previousOuterIndex = m_outerIndex[m_outerSize];
368
+ for (Index j = m_outerSize - 1; j >= 0; --j) {
369
+ StorageIndex innerNNZ = previousOuterIndex - m_outerIndex[j];
370
+ StorageIndex begin = m_outerIndex[j];
371
+ StorageIndex end = begin + innerNNZ;
372
+ StorageIndex target = newOuterIndex[j];
373
+ internal::smart_memmove(innerIndexPtr() + begin, innerIndexPtr() + end, innerIndexPtr() + target);
374
+ internal::smart_memmove(valuePtr() + begin, valuePtr() + end, valuePtr() + target);
375
+ previousOuterIndex = m_outerIndex[j];
376
+ m_outerIndex[j] = newOuterIndex[j];
377
+ m_innerNonZeros[j] = innerNNZ;
378
+ }
379
+ if (m_outerSize > 0)
380
+ m_outerIndex[m_outerSize] = m_outerIndex[m_outerSize - 1] + m_innerNonZeros[m_outerSize - 1] +
381
+ internal::convert_index<StorageIndex>(reserveSizes[m_outerSize - 1]);
382
+
383
+ m_data.resize(m_outerIndex[m_outerSize]);
384
+ } else {
385
+ StorageIndex* newOuterIndex = internal::conditional_aligned_new_auto<StorageIndex, true>(m_outerSize + 1);
386
+
387
+ Index count = 0;
388
+ for (Index j = 0; j < m_outerSize; ++j) {
389
+ newOuterIndex[j] = internal::convert_index<StorageIndex>(count);
390
+ Index alreadyReserved =
391
+ internal::convert_index<Index>(m_outerIndex[j + 1] - m_outerIndex[j] - m_innerNonZeros[j]);
392
+ Index reserveSize = internal::convert_index<Index>(reserveSizes[j]);
393
+ Index toReserve = numext::maxi(reserveSize, alreadyReserved);
394
+ count += toReserve + internal::convert_index<Index>(m_innerNonZeros[j]);
395
+ }
396
+ newOuterIndex[m_outerSize] = internal::convert_index<StorageIndex>(count);
397
+
398
+ m_data.resize(count);
399
+ for (Index j = m_outerSize - 1; j >= 0; --j) {
400
+ StorageIndex innerNNZ = m_innerNonZeros[j];
401
+ StorageIndex begin = m_outerIndex[j];
402
+ StorageIndex target = newOuterIndex[j];
403
+ m_data.moveChunk(begin, target, innerNNZ);
404
+ }
405
+
406
+ std::swap(m_outerIndex, newOuterIndex);
407
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(newOuterIndex, m_outerSize + 1);
418
408
  }
409
+ }
419
410
 
420
- /** \internal
421
- * Must be called after inserting a set of non zero entries using the low level compressed API.
422
- */
423
- inline void finalize()
424
- {
425
- if(isCompressed())
426
- {
427
- StorageIndex size = internal::convert_index<StorageIndex>(m_data.size());
428
- Index i = m_outerSize;
429
- // find the last filled column
430
- while (i>=0 && m_outerIndex[i]==0)
431
- --i;
411
+ public:
412
+ //--- low level purely coherent filling ---
413
+
414
+ /** \internal
415
+ * \returns a reference to the non zero coefficient at position \a row, \a col assuming that:
416
+ * - the nonzero does not already exist
417
+ * - the new coefficient is the last one according to the storage order
418
+ *
419
+ * Before filling a given inner vector you must call the statVec(Index) function.
420
+ *
421
+ * After an insertion session, you should call the finalize() function.
422
+ *
423
+ * \sa insert, insertBackByOuterInner, startVec */
424
+ inline Scalar& insertBack(Index row, Index col) {
425
+ return insertBackByOuterInner(IsRowMajor ? row : col, IsRowMajor ? col : row);
426
+ }
427
+
428
+ /** \internal
429
+ * \sa insertBack, startVec */
430
+ inline Scalar& insertBackByOuterInner(Index outer, Index inner) {
431
+ eigen_assert(Index(m_outerIndex[outer + 1]) == m_data.size() && "Invalid ordered insertion (invalid outer index)");
432
+ eigen_assert((m_outerIndex[outer + 1] - m_outerIndex[outer] == 0 || m_data.index(m_data.size() - 1) < inner) &&
433
+ "Invalid ordered insertion (invalid inner index)");
434
+ StorageIndex p = m_outerIndex[outer + 1];
435
+ ++m_outerIndex[outer + 1];
436
+ m_data.append(Scalar(0), inner);
437
+ return m_data.value(p);
438
+ }
439
+
440
+ /** \internal
441
+ * \warning use it only if you know what you are doing */
442
+ inline Scalar& insertBackByOuterInnerUnordered(Index outer, Index inner) {
443
+ StorageIndex p = m_outerIndex[outer + 1];
444
+ ++m_outerIndex[outer + 1];
445
+ m_data.append(Scalar(0), inner);
446
+ return m_data.value(p);
447
+ }
448
+
449
+ /** \internal
450
+ * \sa insertBack, insertBackByOuterInner */
451
+ inline void startVec(Index outer) {
452
+ eigen_assert(m_outerIndex[outer] == Index(m_data.size()) &&
453
+ "You must call startVec for each inner vector sequentially");
454
+ eigen_assert(m_outerIndex[outer + 1] == 0 && "You must call startVec for each inner vector sequentially");
455
+ m_outerIndex[outer + 1] = m_outerIndex[outer];
456
+ }
457
+
458
+ /** \internal
459
+ * Must be called after inserting a set of non zero entries using the low level compressed API.
460
+ */
461
+ inline void finalize() {
462
+ if (isCompressed()) {
463
+ StorageIndex size = internal::convert_index<StorageIndex>(m_data.size());
464
+ Index i = m_outerSize;
465
+ // find the last filled column
466
+ while (i >= 0 && m_outerIndex[i] == 0) --i;
467
+ ++i;
468
+ while (i <= m_outerSize) {
469
+ m_outerIndex[i] = size;
432
470
  ++i;
433
- while (i<=m_outerSize)
434
- {
435
- m_outerIndex[i] = size;
436
- ++i;
437
- }
438
471
  }
439
472
  }
473
+ }
474
+
475
+ // remove outer vectors j, j+1 ... j+num-1 and resize the matrix
476
+ void removeOuterVectors(Index j, Index num = 1) {
477
+ eigen_assert(num >= 0 && j >= 0 && j + num <= m_outerSize && "Invalid parameters");
478
+
479
+ const Index newRows = IsRowMajor ? m_outerSize - num : rows();
480
+ const Index newCols = IsRowMajor ? cols() : m_outerSize - num;
481
+
482
+ const Index begin = j + num;
483
+ const Index end = m_outerSize;
484
+ const Index target = j;
485
+
486
+ // if the removed vectors are not empty, uncompress the matrix
487
+ if (m_outerIndex[j + num] > m_outerIndex[j]) uncompress();
488
+
489
+ // shift m_outerIndex and m_innerNonZeros [num] to the left
490
+ internal::smart_memmove(m_outerIndex + begin, m_outerIndex + end + 1, m_outerIndex + target);
491
+ if (!isCompressed())
492
+ internal::smart_memmove(m_innerNonZeros + begin, m_innerNonZeros + end, m_innerNonZeros + target);
493
+
494
+ // if m_outerIndex[0] > 0, shift the data within the first vector while it is easy to do so
495
+ if (m_outerIndex[0] > StorageIndex(0)) {
496
+ uncompress();
497
+ const Index from = internal::convert_index<Index>(m_outerIndex[0]);
498
+ const Index to = Index(0);
499
+ const Index chunkSize = internal::convert_index<Index>(m_innerNonZeros[0]);
500
+ m_data.moveChunk(from, to, chunkSize);
501
+ m_outerIndex[0] = StorageIndex(0);
502
+ }
440
503
 
441
- //---
504
+ // truncate the matrix to the smaller size
505
+ conservativeResize(newRows, newCols);
506
+ }
442
507
 
443
- template<typename InputIterators>
444
- void setFromTriplets(const InputIterators& begin, const InputIterators& end);
508
+ // insert empty outer vectors at indices j, j+1 ... j+num-1 and resize the matrix
509
+ void insertEmptyOuterVectors(Index j, Index num = 1) {
510
+ using std::fill_n;
511
+ eigen_assert(num >= 0 && j >= 0 && j < m_outerSize && "Invalid parameters");
445
512
 
446
- template<typename InputIterators,typename DupFunctor>
447
- void setFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func);
513
+ const Index newRows = IsRowMajor ? m_outerSize + num : rows();
514
+ const Index newCols = IsRowMajor ? cols() : m_outerSize + num;
448
515
 
449
- void sumupDuplicates() { collapseDuplicates(internal::scalar_sum_op<Scalar,Scalar>()); }
516
+ const Index begin = j;
517
+ const Index end = m_outerSize;
518
+ const Index target = j + num;
450
519
 
451
- template<typename DupFunctor>
452
- void collapseDuplicates(DupFunctor dup_func = DupFunctor());
520
+ // expand the matrix to the larger size
521
+ conservativeResize(newRows, newCols);
453
522
 
454
- //---
455
-
456
- /** \internal
457
- * same as insert(Index,Index) except that the indices are given relative to the storage order */
458
- Scalar& insertByOuterInner(Index j, Index i)
459
- {
460
- return insert(IsRowMajor ? j : i, IsRowMajor ? i : j);
523
+ // shift m_outerIndex and m_innerNonZeros [num] to the right
524
+ internal::smart_memmove(m_outerIndex + begin, m_outerIndex + end + 1, m_outerIndex + target);
525
+ // m_outerIndex[begin] == m_outerIndex[target], set all indices in this range to same value
526
+ fill_n(m_outerIndex + begin, num, m_outerIndex[begin]);
527
+
528
+ if (!isCompressed()) {
529
+ internal::smart_memmove(m_innerNonZeros + begin, m_innerNonZeros + end, m_innerNonZeros + target);
530
+ // set the nonzeros of the newly inserted vectors to 0
531
+ fill_n(m_innerNonZeros + begin, num, StorageIndex(0));
461
532
  }
533
+ }
462
534
 
463
- /** Turns the matrix into the \em compressed format.
464
- */
465
- void makeCompressed()
466
- {
467
- if(isCompressed())
468
- return;
469
-
470
- eigen_internal_assert(m_outerIndex!=0 && m_outerSize>0);
471
-
472
- Index oldStart = m_outerIndex[1];
473
- m_outerIndex[1] = m_innerNonZeros[0];
474
- for(Index j=1; j<m_outerSize; ++j)
475
- {
476
- Index nextOldStart = m_outerIndex[j+1];
477
- Index offset = oldStart - m_outerIndex[j];
478
- if(offset>0)
479
- {
480
- for(Index k=0; k<m_innerNonZeros[j]; ++k)
481
- {
482
- m_data.index(m_outerIndex[j]+k) = m_data.index(oldStart+k);
483
- m_data.value(m_outerIndex[j]+k) = m_data.value(oldStart+k);
484
- }
485
- }
486
- m_outerIndex[j+1] = m_outerIndex[j] + m_innerNonZeros[j];
487
- oldStart = nextOldStart;
535
+ template <typename InputIterators>
536
+ void setFromTriplets(const InputIterators& begin, const InputIterators& end);
537
+
538
+ template <typename InputIterators, typename DupFunctor>
539
+ void setFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func);
540
+
541
+ template <typename Derived, typename DupFunctor>
542
+ void collapseDuplicates(DenseBase<Derived>& wi, DupFunctor dup_func = DupFunctor());
543
+
544
+ template <typename InputIterators>
545
+ void setFromSortedTriplets(const InputIterators& begin, const InputIterators& end);
546
+
547
+ template <typename InputIterators, typename DupFunctor>
548
+ void setFromSortedTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func);
549
+
550
+ template <typename InputIterators>
551
+ void insertFromTriplets(const InputIterators& begin, const InputIterators& end);
552
+
553
+ template <typename InputIterators, typename DupFunctor>
554
+ void insertFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func);
555
+
556
+ template <typename InputIterators>
557
+ void insertFromSortedTriplets(const InputIterators& begin, const InputIterators& end);
558
+
559
+ template <typename InputIterators, typename DupFunctor>
560
+ void insertFromSortedTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func);
561
+
562
+ //---
563
+
564
+ /** \internal
565
+ * same as insert(Index,Index) except that the indices are given relative to the storage order */
566
+ Scalar& insertByOuterInner(Index j, Index i) {
567
+ eigen_assert(j >= 0 && j < m_outerSize && "invalid outer index");
568
+ eigen_assert(i >= 0 && i < m_innerSize && "invalid inner index");
569
+ Index start = m_outerIndex[j];
570
+ Index end = isCompressed() ? m_outerIndex[j + 1] : start + m_innerNonZeros[j];
571
+ Index dst = start == end ? end : m_data.searchLowerIndex(start, end, i);
572
+ if (dst == end) {
573
+ Index capacity = m_outerIndex[j + 1] - end;
574
+ if (capacity > 0) {
575
+ // implies uncompressed: push to back of vector
576
+ m_innerNonZeros[j]++;
577
+ m_data.index(end) = StorageIndex(i);
578
+ m_data.value(end) = Scalar(0);
579
+ return m_data.value(end);
488
580
  }
489
- std::free(m_innerNonZeros);
490
- m_innerNonZeros = 0;
491
- m_data.resize(m_outerIndex[m_outerSize]);
492
- m_data.squeeze();
493
581
  }
582
+ eigen_assert((dst == end || m_data.index(dst) != i) &&
583
+ "you cannot insert an element that already exists, you must call coeffRef to this end");
584
+ return insertAtByOuterInner(j, i, dst);
585
+ }
494
586
 
495
- /** Turns the matrix into the uncompressed mode */
496
- void uncompress()
497
- {
498
- if(m_innerNonZeros != 0)
499
- return;
500
- m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex)));
501
- for (Index i = 0; i < m_outerSize; i++)
502
- {
503
- m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i];
587
+ /** Turns the matrix into the \em compressed format.
588
+ */
589
+ void makeCompressed() {
590
+ if (isCompressed()) return;
591
+
592
+ eigen_internal_assert(m_outerIndex != 0 && m_outerSize > 0);
593
+
594
+ StorageIndex start = m_outerIndex[1];
595
+ m_outerIndex[1] = m_innerNonZeros[0];
596
+ // try to move fewer, larger contiguous chunks
597
+ Index copyStart = start;
598
+ Index copyTarget = m_innerNonZeros[0];
599
+ for (Index j = 1; j < m_outerSize; j++) {
600
+ StorageIndex end = start + m_innerNonZeros[j];
601
+ StorageIndex nextStart = m_outerIndex[j + 1];
602
+ // dont forget to move the last chunk!
603
+ bool breakUpCopy = (end != nextStart) || (j == m_outerSize - 1);
604
+ if (breakUpCopy) {
605
+ Index chunkSize = end - copyStart;
606
+ if (chunkSize > 0) m_data.moveChunk(copyStart, copyTarget, chunkSize);
607
+ copyStart = nextStart;
608
+ copyTarget += chunkSize;
504
609
  }
610
+ start = nextStart;
611
+ m_outerIndex[j + 1] = m_outerIndex[j] + m_innerNonZeros[j];
505
612
  }
506
-
507
- /** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerence \a epsilon */
508
- void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision())
509
- {
510
- prune(default_prunning_func(reference,epsilon));
613
+ m_data.resize(m_outerIndex[m_outerSize]);
614
+
615
+ // release as much memory as possible
616
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
617
+ m_innerNonZeros = 0;
618
+ m_data.squeeze();
619
+ }
620
+
621
+ /** Turns the matrix into the uncompressed mode */
622
+ void uncompress() {
623
+ if (!isCompressed()) return;
624
+ m_innerNonZeros = internal::conditional_aligned_new_auto<StorageIndex, true>(m_outerSize);
625
+ if (m_outerIndex[m_outerSize] == 0) {
626
+ using std::fill_n;
627
+ fill_n(m_innerNonZeros, m_outerSize, StorageIndex(0));
628
+ } else {
629
+ for (Index j = 0; j < m_outerSize; j++) m_innerNonZeros[j] = m_outerIndex[j + 1] - m_outerIndex[j];
511
630
  }
512
-
513
- /** Turns the matrix into compressed format, and suppresses all nonzeros which do not satisfy the predicate \a keep.
514
- * The functor type \a KeepFunc must implement the following function:
515
- * \code
516
- * bool operator() (const Index& row, const Index& col, const Scalar& value) const;
517
- * \endcode
518
- * \sa prune(Scalar,RealScalar)
519
- */
520
- template<typename KeepFunc>
521
- void prune(const KeepFunc& keep = KeepFunc())
522
- {
523
- // TODO optimize the uncompressed mode to avoid moving and allocating the data twice
524
- makeCompressed();
631
+ }
525
632
 
526
- StorageIndex k = 0;
527
- for(Index j=0; j<m_outerSize; ++j)
528
- {
529
- Index previousStart = m_outerIndex[j];
633
+ /** Suppresses all nonzeros which are \b much \b smaller \b than \a reference under the tolerance \a epsilon */
634
+ void prune(const Scalar& reference, const RealScalar& epsilon = NumTraits<RealScalar>::dummy_precision()) {
635
+ prune(default_prunning_func(reference, epsilon));
636
+ }
637
+
638
+ /** Turns the matrix into compressed format, and suppresses all nonzeros which do not satisfy the predicate \a keep.
639
+ * The functor type \a KeepFunc must implement the following function:
640
+ * \code
641
+ * bool operator() (const Index& row, const Index& col, const Scalar& value) const;
642
+ * \endcode
643
+ * \sa prune(Scalar,RealScalar)
644
+ */
645
+ template <typename KeepFunc>
646
+ void prune(const KeepFunc& keep = KeepFunc()) {
647
+ StorageIndex k = 0;
648
+ for (Index j = 0; j < m_outerSize; ++j) {
649
+ StorageIndex previousStart = m_outerIndex[j];
650
+ if (isCompressed())
530
651
  m_outerIndex[j] = k;
531
- Index end = m_outerIndex[j+1];
532
- for(Index i=previousStart; i<end; ++i)
533
- {
534
- if(keep(IsRowMajor?j:m_data.index(i), IsRowMajor?m_data.index(i):j, m_data.value(i)))
535
- {
536
- m_data.value(k) = m_data.value(i);
537
- m_data.index(k) = m_data.index(i);
538
- ++k;
539
- }
540
- }
652
+ else
653
+ k = m_outerIndex[j];
654
+ StorageIndex end = isCompressed() ? m_outerIndex[j + 1] : previousStart + m_innerNonZeros[j];
655
+ for (StorageIndex i = previousStart; i < end; ++i) {
656
+ StorageIndex row = IsRowMajor ? StorageIndex(j) : m_data.index(i);
657
+ StorageIndex col = IsRowMajor ? m_data.index(i) : StorageIndex(j);
658
+ bool keepEntry = keep(row, col, m_data.value(i));
659
+ if (keepEntry) {
660
+ m_data.value(k) = m_data.value(i);
661
+ m_data.index(k) = m_data.index(i);
662
+ ++k;
663
+ } else if (!isCompressed())
664
+ m_innerNonZeros[j]--;
541
665
  }
666
+ }
667
+ if (isCompressed()) {
542
668
  m_outerIndex[m_outerSize] = k;
543
- m_data.resize(k,0);
669
+ m_data.resize(k, 0);
544
670
  }
671
+ }
545
672
 
546
- /** Resizes the matrix to a \a rows x \a cols matrix leaving old values untouched.
547
- *
548
- * If the sizes of the matrix are decreased, then the matrix is turned to \b uncompressed-mode
549
- * and the storage of the out of bounds coefficients is kept and reserved.
550
- * Call makeCompressed() to pack the entries and squeeze extra memory.
551
- *
552
- * \sa reserve(), setZero(), makeCompressed()
553
- */
554
- void conservativeResize(Index rows, Index cols)
555
- {
556
- // No change
557
- if (this->rows() == rows && this->cols() == cols) return;
558
-
559
- // If one dimension is null, then there is nothing to be preserved
560
- if(rows==0 || cols==0) return resize(rows,cols);
561
-
562
- Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows();
563
- Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols();
564
- StorageIndex newInnerSize = convert_index(IsRowMajor ? cols : rows);
565
-
566
- // Deals with inner non zeros
567
- if (m_innerNonZeros)
568
- {
569
- // Resize m_innerNonZeros
570
- StorageIndex *newInnerNonZeros = static_cast<StorageIndex*>(std::realloc(m_innerNonZeros, (m_outerSize + outerChange) * sizeof(StorageIndex)));
571
- if (!newInnerNonZeros) internal::throw_std_bad_alloc();
572
- m_innerNonZeros = newInnerNonZeros;
573
-
574
- for(Index i=m_outerSize; i<m_outerSize+outerChange; i++)
575
- m_innerNonZeros[i] = 0;
576
- }
577
- else if (innerChange < 0)
578
- {
579
- // Inner size decreased: allocate a new m_innerNonZeros
580
- m_innerNonZeros = static_cast<StorageIndex*>(std::malloc((m_outerSize+outerChange+1) * sizeof(StorageIndex)));
581
- if (!m_innerNonZeros) internal::throw_std_bad_alloc();
582
- for(Index i = 0; i < m_outerSize; i++)
583
- m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i];
673
+ /** Resizes the matrix to a \a rows x \a cols matrix leaving old values untouched.
674
+ *
675
+ * If the sizes of the matrix are decreased, then the matrix is turned to \b uncompressed-mode
676
+ * and the storage of the out of bounds coefficients is kept and reserved.
677
+ * Call makeCompressed() to pack the entries and squeeze extra memory.
678
+ *
679
+ * \sa reserve(), setZero(), makeCompressed()
680
+ */
681
+ void conservativeResize(Index rows, Index cols) {
682
+ // If one dimension is null, then there is nothing to be preserved
683
+ if (rows == 0 || cols == 0) return resize(rows, cols);
684
+
685
+ Index newOuterSize = IsRowMajor ? rows : cols;
686
+ Index newInnerSize = IsRowMajor ? cols : rows;
687
+
688
+ Index innerChange = newInnerSize - m_innerSize;
689
+ Index outerChange = newOuterSize - m_outerSize;
690
+
691
+ if (outerChange != 0) {
692
+ m_outerIndex = internal::conditional_aligned_realloc_new_auto<StorageIndex, true>(m_outerIndex, newOuterSize + 1,
693
+ m_outerSize + 1);
694
+
695
+ if (!isCompressed())
696
+ m_innerNonZeros = internal::conditional_aligned_realloc_new_auto<StorageIndex, true>(m_innerNonZeros,
697
+ newOuterSize, m_outerSize);
698
+
699
+ if (outerChange > 0) {
700
+ StorageIndex lastIdx = m_outerSize == 0 ? StorageIndex(0) : m_outerIndex[m_outerSize];
701
+ using std::fill_n;
702
+ fill_n(m_outerIndex + m_outerSize, outerChange + 1, lastIdx);
703
+
704
+ if (!isCompressed()) fill_n(m_innerNonZeros + m_outerSize, outerChange, StorageIndex(0));
584
705
  }
585
-
586
- // Change the m_innerNonZeros in case of a decrease of inner size
587
- if (m_innerNonZeros && innerChange < 0)
588
- {
589
- for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++)
590
- {
591
- StorageIndex &n = m_innerNonZeros[i];
592
- StorageIndex start = m_outerIndex[i];
593
- while (n > 0 && m_data.index(start+n-1) >= newInnerSize) --n;
594
- }
595
- }
596
-
597
- m_innerSize = newInnerSize;
598
-
599
- // Re-allocate outer index structure if necessary
600
- if (outerChange == 0)
601
- return;
602
-
603
- StorageIndex *newOuterIndex = static_cast<StorageIndex*>(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(StorageIndex)));
604
- if (!newOuterIndex) internal::throw_std_bad_alloc();
605
- m_outerIndex = newOuterIndex;
606
- if (outerChange > 0)
607
- {
608
- StorageIndex last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize];
609
- for(Index i=m_outerSize; i<m_outerSize+outerChange+1; i++)
610
- m_outerIndex[i] = last;
611
- }
612
- m_outerSize += outerChange;
613
706
  }
614
-
615
- /** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero.
616
- *
617
- * This function does not free the currently allocated memory. To release as much as memory as possible,
618
- * call \code mat.data().squeeze(); \endcode after resizing it.
619
- *
620
- * \sa reserve(), setZero()
621
- */
622
- void resize(Index rows, Index cols)
623
- {
624
- const Index outerSize = IsRowMajor ? rows : cols;
625
- m_innerSize = IsRowMajor ? cols : rows;
626
- m_data.clear();
627
- if (m_outerSize != outerSize || m_outerSize==0)
628
- {
629
- std::free(m_outerIndex);
630
- m_outerIndex = static_cast<StorageIndex*>(std::malloc((outerSize + 1) * sizeof(StorageIndex)));
631
- if (!m_outerIndex) internal::throw_std_bad_alloc();
632
-
633
- m_outerSize = outerSize;
634
- }
635
- if(m_innerNonZeros)
636
- {
637
- std::free(m_innerNonZeros);
638
- m_innerNonZeros = 0;
707
+ m_outerSize = newOuterSize;
708
+
709
+ if (innerChange < 0) {
710
+ for (Index j = 0; j < m_outerSize; j++) {
711
+ Index start = m_outerIndex[j];
712
+ Index end = isCompressed() ? m_outerIndex[j + 1] : start + m_innerNonZeros[j];
713
+ Index lb = m_data.searchLowerIndex(start, end, newInnerSize);
714
+ if (lb != end) {
715
+ uncompress();
716
+ m_innerNonZeros[j] = StorageIndex(lb - start);
717
+ }
639
718
  }
640
- memset(m_outerIndex, 0, (m_outerSize+1)*sizeof(StorageIndex));
641
719
  }
720
+ m_innerSize = newInnerSize;
642
721
 
643
- /** \internal
644
- * Resize the nonzero vector to \a size */
645
- void resizeNonZeros(Index size)
646
- {
647
- m_data.resize(size);
648
- }
722
+ Index newSize = m_outerIndex[m_outerSize];
723
+ eigen_assert(newSize <= m_data.size());
724
+ m_data.resize(newSize);
725
+ }
649
726
 
650
- /** \returns a const expression of the diagonal coefficients. */
651
- const ConstDiagonalReturnType diagonal() const { return ConstDiagonalReturnType(*this); }
652
-
653
- /** \returns a read-write expression of the diagonal coefficients.
654
- * \warning If the diagonal entries are written, then all diagonal
655
- * entries \b must already exist, otherwise an assertion will be raised.
656
- */
657
- DiagonalReturnType diagonal() { return DiagonalReturnType(*this); }
658
-
659
- /** Default constructor yielding an empty \c 0 \c x \c 0 matrix */
660
- inline SparseMatrix()
661
- : m_outerSize(-1), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
662
- {
663
- check_template_parameters();
664
- resize(0, 0);
727
+ /** Resizes the matrix to a \a rows x \a cols matrix and initializes it to zero.
728
+ *
729
+ * This function does not free the currently allocated memory. To release as much as memory as possible,
730
+ * call \code mat.data().squeeze(); \endcode after resizing it.
731
+ *
732
+ * \sa reserve(), setZero()
733
+ */
734
+ void resize(Index rows, Index cols) {
735
+ const Index outerSize = IsRowMajor ? rows : cols;
736
+ m_innerSize = IsRowMajor ? cols : rows;
737
+ m_data.clear();
738
+
739
+ if ((m_outerIndex == 0) || (m_outerSize != outerSize)) {
740
+ m_outerIndex = internal::conditional_aligned_realloc_new_auto<StorageIndex, true>(m_outerIndex, outerSize + 1,
741
+ m_outerSize + 1);
742
+ m_outerSize = outerSize;
665
743
  }
666
744
 
667
- /** Constructs a \a rows \c x \a cols empty matrix */
668
- inline SparseMatrix(Index rows, Index cols)
669
- : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
670
- {
671
- check_template_parameters();
672
- resize(rows, cols);
673
- }
745
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
746
+ m_innerNonZeros = 0;
674
747
 
675
- /** Constructs a sparse matrix from the sparse expression \a other */
676
- template<typename OtherDerived>
677
- inline SparseMatrix(const SparseMatrixBase<OtherDerived>& other)
678
- : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
679
- {
680
- EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
681
- YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
682
- check_template_parameters();
683
- const bool needToTranspose = (Flags & RowMajorBit) != (internal::evaluator<OtherDerived>::Flags & RowMajorBit);
684
- if (needToTranspose)
685
- *this = other.derived();
686
- else
687
- {
688
- #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
689
- EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
690
- #endif
691
- internal::call_assignment_no_alias(*this, other.derived());
692
- }
693
- }
694
-
695
- /** Constructs a sparse matrix from the sparse selfadjoint view \a other */
696
- template<typename OtherDerived, unsigned int UpLo>
697
- inline SparseMatrix(const SparseSelfAdjointView<OtherDerived, UpLo>& other)
698
- : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
699
- {
700
- check_template_parameters();
701
- Base::operator=(other);
702
- }
748
+ using std::fill_n;
749
+ fill_n(m_outerIndex, m_outerSize + 1, StorageIndex(0));
750
+ }
703
751
 
704
- /** Copy constructor (it performs a deep copy) */
705
- inline SparseMatrix(const SparseMatrix& other)
706
- : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
707
- {
708
- check_template_parameters();
709
- *this = other.derived();
710
- }
752
+ /** \internal
753
+ * Resize the nonzero vector to \a size */
754
+ void resizeNonZeros(Index size) { m_data.resize(size); }
711
755
 
712
- /** \brief Copy constructor with in-place evaluation */
713
- template<typename OtherDerived>
714
- SparseMatrix(const ReturnByValue<OtherDerived>& other)
715
- : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
716
- {
717
- check_template_parameters();
718
- initAssignment(other);
719
- other.evalTo(*this);
720
- }
721
-
722
- /** \brief Copy constructor with in-place evaluation */
723
- template<typename OtherDerived>
724
- explicit SparseMatrix(const DiagonalBase<OtherDerived>& other)
725
- : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
726
- {
727
- check_template_parameters();
756
+ /** \returns a const expression of the diagonal coefficients. */
757
+ const ConstDiagonalReturnType diagonal() const { return ConstDiagonalReturnType(*this); }
758
+
759
+ /** \returns a read-write expression of the diagonal coefficients.
760
+ * \warning If the diagonal entries are written, then all diagonal
761
+ * entries \b must already exist, otherwise an assertion will be raised.
762
+ */
763
+ DiagonalReturnType diagonal() { return DiagonalReturnType(*this); }
764
+
765
+ /** Default constructor yielding an empty \c 0 \c x \c 0 matrix */
766
+ inline SparseMatrix() : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) { resize(0, 0); }
767
+
768
+ /** Constructs a \a rows \c x \a cols empty matrix */
769
+ inline SparseMatrix(Index rows, Index cols) : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
770
+ resize(rows, cols);
771
+ }
772
+
773
+ /** Constructs a sparse matrix from the sparse expression \a other */
774
+ template <typename OtherDerived>
775
+ inline SparseMatrix(const SparseMatrixBase<OtherDerived>& other)
776
+ : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
777
+ EIGEN_STATIC_ASSERT(
778
+ (internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
779
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
780
+ const bool needToTranspose = (Flags & RowMajorBit) != (internal::evaluator<OtherDerived>::Flags & RowMajorBit);
781
+ if (needToTranspose)
728
782
  *this = other.derived();
783
+ else {
784
+ #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
785
+ EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
786
+ #endif
787
+ internal::call_assignment_no_alias(*this, other.derived());
729
788
  }
789
+ }
730
790
 
731
- /** Swaps the content of two sparse matrices of the same type.
732
- * This is a fast operation that simply swaps the underlying pointers and parameters. */
733
- inline void swap(SparseMatrix& other)
734
- {
735
- //EIGEN_DBG_SPARSE(std::cout << "SparseMatrix:: swap\n");
736
- std::swap(m_outerIndex, other.m_outerIndex);
737
- std::swap(m_innerSize, other.m_innerSize);
738
- std::swap(m_outerSize, other.m_outerSize);
739
- std::swap(m_innerNonZeros, other.m_innerNonZeros);
740
- m_data.swap(other.m_data);
741
- }
791
+ /** Constructs a sparse matrix from the sparse selfadjoint view \a other */
792
+ template <typename OtherDerived, unsigned int UpLo>
793
+ inline SparseMatrix(const SparseSelfAdjointView<OtherDerived, UpLo>& other)
794
+ : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
795
+ Base::operator=(other);
796
+ }
742
797
 
743
- /** Sets *this to the identity matrix.
744
- * This function also turns the matrix into compressed mode, and drop any reserved memory. */
745
- inline void setIdentity()
746
- {
747
- eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
748
- this->m_data.resize(rows());
749
- Eigen::Map<IndexVector>(this->m_data.indexPtr(), rows()).setLinSpaced(0, StorageIndex(rows()-1));
750
- Eigen::Map<ScalarVector>(this->m_data.valuePtr(), rows()).setOnes();
751
- Eigen::Map<IndexVector>(this->m_outerIndex, rows()+1).setLinSpaced(0, StorageIndex(rows()));
752
- std::free(m_innerNonZeros);
753
- m_innerNonZeros = 0;
754
- }
755
- inline SparseMatrix& operator=(const SparseMatrix& other)
756
- {
757
- if (other.isRValue())
758
- {
759
- swap(other.const_cast_derived());
760
- }
761
- else if(this!=&other)
762
- {
763
- #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
764
- EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
765
- #endif
766
- initAssignment(other);
767
- if(other.isCompressed())
768
- {
769
- internal::smart_copy(other.m_outerIndex, other.m_outerIndex + m_outerSize + 1, m_outerIndex);
770
- m_data = other.m_data;
771
- }
772
- else
773
- {
774
- Base::operator=(other);
775
- }
798
+ /** Move constructor */
799
+ inline SparseMatrix(SparseMatrix&& other) : SparseMatrix() { this->swap(other); }
800
+
801
+ template <typename OtherDerived>
802
+ inline SparseMatrix(SparseCompressedBase<OtherDerived>&& other) : SparseMatrix() {
803
+ *this = other.derived().markAsRValue();
804
+ }
805
+
806
+ /** Copy constructor (it performs a deep copy) */
807
+ inline SparseMatrix(const SparseMatrix& other)
808
+ : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
809
+ *this = other.derived();
810
+ }
811
+
812
+ /** \brief Copy constructor with in-place evaluation */
813
+ template <typename OtherDerived>
814
+ SparseMatrix(const ReturnByValue<OtherDerived>& other)
815
+ : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
816
+ initAssignment(other);
817
+ other.evalTo(*this);
818
+ }
819
+
820
+ /** \brief Copy constructor with in-place evaluation */
821
+ template <typename OtherDerived>
822
+ explicit SparseMatrix(const DiagonalBase<OtherDerived>& other)
823
+ : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) {
824
+ *this = other.derived();
825
+ }
826
+
827
+ /** Swaps the content of two sparse matrices of the same type.
828
+ * This is a fast operation that simply swaps the underlying pointers and parameters. */
829
+ inline void swap(SparseMatrix& other) {
830
+ // EIGEN_DBG_SPARSE(std::cout << "SparseMatrix:: swap\n");
831
+ std::swap(m_outerIndex, other.m_outerIndex);
832
+ std::swap(m_innerSize, other.m_innerSize);
833
+ std::swap(m_outerSize, other.m_outerSize);
834
+ std::swap(m_innerNonZeros, other.m_innerNonZeros);
835
+ m_data.swap(other.m_data);
836
+ }
837
+ /** Free-function swap. */
838
+ friend EIGEN_DEVICE_FUNC void swap(SparseMatrix& a, SparseMatrix& b) { a.swap(b); }
839
+
840
+ /** Sets *this to the identity matrix.
841
+ * This function also turns the matrix into compressed mode, and drop any reserved memory. */
842
+ inline void setIdentity() {
843
+ eigen_assert(m_outerSize == m_innerSize && "ONLY FOR SQUARED MATRICES");
844
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
845
+ m_innerNonZeros = 0;
846
+ m_data.resize(m_outerSize);
847
+ // is it necessary to squeeze?
848
+ m_data.squeeze();
849
+ std::iota(m_outerIndex, m_outerIndex + m_outerSize + 1, StorageIndex(0));
850
+ std::iota(innerIndexPtr(), innerIndexPtr() + m_outerSize, StorageIndex(0));
851
+ using std::fill_n;
852
+ fill_n(valuePtr(), m_outerSize, Scalar(1));
853
+ }
854
+
855
+ inline SparseMatrix& operator=(const SparseMatrix& other) {
856
+ if (other.isRValue()) {
857
+ swap(other.const_cast_derived());
858
+ } else if (this != &other) {
859
+ #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
860
+ EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
861
+ #endif
862
+ initAssignment(other);
863
+ if (other.isCompressed()) {
864
+ internal::smart_copy(other.m_outerIndex, other.m_outerIndex + m_outerSize + 1, m_outerIndex);
865
+ m_data = other.m_data;
866
+ } else {
867
+ Base::operator=(other);
776
868
  }
777
- return *this;
778
869
  }
870
+ return *this;
871
+ }
779
872
 
780
- #ifndef EIGEN_PARSED_BY_DOXYGEN
781
- template<typename OtherDerived>
782
- inline SparseMatrix& operator=(const EigenBase<OtherDerived>& other)
783
- { return Base::operator=(other.derived()); }
784
- #endif // EIGEN_PARSED_BY_DOXYGEN
873
+ inline SparseMatrix& operator=(SparseMatrix&& other) {
874
+ this->swap(other);
875
+ return *this;
876
+ }
877
+
878
+ template <typename OtherDerived>
879
+ inline SparseMatrix& operator=(const EigenBase<OtherDerived>& other) {
880
+ return Base::operator=(other.derived());
881
+ }
785
882
 
786
- template<typename OtherDerived>
787
- EIGEN_DONT_INLINE SparseMatrix& operator=(const SparseMatrixBase<OtherDerived>& other);
883
+ template <typename Lhs, typename Rhs>
884
+ inline SparseMatrix& operator=(const Product<Lhs, Rhs, AliasFreeProduct>& other);
788
885
 
789
- friend std::ostream & operator << (std::ostream & s, const SparseMatrix& m)
790
- {
791
- EIGEN_DBG_SPARSE(
792
- s << "Nonzero entries:\n";
793
- if(m.isCompressed())
794
- {
795
- for (Index i=0; i<m.nonZeros(); ++i)
796
- s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") ";
797
- }
798
- else
799
- {
800
- for (Index i=0; i<m.outerSize(); ++i)
801
- {
886
+ template <typename OtherDerived>
887
+ EIGEN_DONT_INLINE SparseMatrix& operator=(const SparseMatrixBase<OtherDerived>& other);
888
+
889
+ template <typename OtherDerived>
890
+ inline SparseMatrix& operator=(SparseCompressedBase<OtherDerived>&& other) {
891
+ *this = other.derived().markAsRValue();
892
+ return *this;
893
+ }
894
+
895
+ #ifndef EIGEN_NO_IO
896
+ friend std::ostream& operator<<(std::ostream& s, const SparseMatrix& m) {
897
+ EIGEN_DBG_SPARSE(
898
+ s << "Nonzero entries:\n"; if (m.isCompressed()) {
899
+ for (Index i = 0; i < m.nonZeros(); ++i) s << "(" << m.m_data.value(i) << "," << m.m_data.index(i) << ") ";
900
+ } else {
901
+ for (Index i = 0; i < m.outerSize(); ++i) {
802
902
  Index p = m.m_outerIndex[i];
803
- Index pe = m.m_outerIndex[i]+m.m_innerNonZeros[i];
804
- Index k=p;
805
- for (; k<pe; ++k) {
903
+ Index pe = m.m_outerIndex[i] + m.m_innerNonZeros[i];
904
+ Index k = p;
905
+ for (; k < pe; ++k) {
806
906
  s << "(" << m.m_data.value(k) << "," << m.m_data.index(k) << ") ";
807
907
  }
808
- for (; k<m.m_outerIndex[i+1]; ++k) {
908
+ for (; k < m.m_outerIndex[i + 1]; ++k) {
809
909
  s << "(_,_) ";
810
910
  }
811
911
  }
812
- }
813
- s << std::endl;
814
- s << std::endl;
815
- s << "Outer pointers:\n";
816
- for (Index i=0; i<m.outerSize(); ++i) {
817
- s << m.m_outerIndex[i] << " ";
818
- }
819
- s << " $" << std::endl;
820
- if(!m.isCompressed())
821
- {
912
+ } s << std::endl;
913
+ s << std::endl; s << "Outer pointers:\n";
914
+ for (Index i = 0; i < m.outerSize(); ++i) { s << m.m_outerIndex[i] << " "; } s << " $" << std::endl;
915
+ if (!m.isCompressed()) {
822
916
  s << "Inner non zeros:\n";
823
- for (Index i=0; i<m.outerSize(); ++i) {
917
+ for (Index i = 0; i < m.outerSize(); ++i) {
824
918
  s << m.m_innerNonZeros[i] << " ";
825
919
  }
826
920
  s << " $" << std::endl;
827
- }
828
- s << std::endl;
829
- );
830
- s << static_cast<const SparseMatrixBase<SparseMatrix>&>(m);
831
- return s;
832
- }
921
+ } s
922
+ << std::endl;);
923
+ s << static_cast<const SparseMatrixBase<SparseMatrix>&>(m);
924
+ return s;
925
+ }
926
+ #endif
833
927
 
834
- /** Destructor */
835
- inline ~SparseMatrix()
836
- {
837
- std::free(m_outerIndex);
838
- std::free(m_innerNonZeros);
839
- }
928
+ /** Destructor */
929
+ inline ~SparseMatrix() {
930
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_outerIndex, m_outerSize + 1);
931
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
932
+ }
840
933
 
841
- /** Overloaded for performance */
842
- Scalar sum() const;
843
-
844
- # ifdef EIGEN_SPARSEMATRIX_PLUGIN
845
- # include EIGEN_SPARSEMATRIX_PLUGIN
846
- # endif
934
+ /** Overloaded for performance */
935
+ Scalar sum() const;
847
936
 
848
- protected:
937
+ #ifdef EIGEN_SPARSEMATRIX_PLUGIN
938
+ #include EIGEN_SPARSEMATRIX_PLUGIN
939
+ #endif
849
940
 
850
- template<typename Other>
851
- void initAssignment(const Other& other)
852
- {
853
- resize(other.rows(), other.cols());
854
- if(m_innerNonZeros)
855
- {
856
- std::free(m_innerNonZeros);
857
- m_innerNonZeros = 0;
858
- }
859
- }
941
+ protected:
942
+ template <typename Other>
943
+ void initAssignment(const Other& other) {
944
+ resize(other.rows(), other.cols());
945
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
946
+ m_innerNonZeros = 0;
947
+ }
860
948
 
861
- /** \internal
862
- * \sa insert(Index,Index) */
863
- EIGEN_DONT_INLINE Scalar& insertCompressed(Index row, Index col);
949
+ /** \internal
950
+ * \sa insert(Index,Index) */
951
+ EIGEN_DEPRECATED EIGEN_DONT_INLINE Scalar& insertCompressed(Index row, Index col);
864
952
 
865
- /** \internal
866
- * A vector object that is equal to 0 everywhere but v at the position i */
867
- class SingletonVector
868
- {
869
- StorageIndex m_index;
870
- StorageIndex m_value;
871
- public:
872
- typedef StorageIndex value_type;
873
- SingletonVector(Index i, Index v)
874
- : m_index(convert_index(i)), m_value(convert_index(v))
875
- {}
876
-
877
- StorageIndex operator[](Index i) const { return i==m_index ? m_value : 0; }
878
- };
879
-
880
- /** \internal
881
- * \sa insert(Index,Index) */
882
- EIGEN_DONT_INLINE Scalar& insertUncompressed(Index row, Index col);
883
-
884
- public:
885
- /** \internal
886
- * \sa insert(Index,Index) */
887
- EIGEN_STRONG_INLINE Scalar& insertBackUncompressed(Index row, Index col)
888
- {
889
- const Index outer = IsRowMajor ? row : col;
890
- const Index inner = IsRowMajor ? col : row;
953
+ /** \internal
954
+ * A vector object that is equal to 0 everywhere but v at the position i */
955
+ class SingletonVector {
956
+ StorageIndex m_index;
957
+ StorageIndex m_value;
958
+
959
+ public:
960
+ typedef StorageIndex value_type;
961
+ SingletonVector(Index i, Index v) : m_index(convert_index(i)), m_value(convert_index(v)) {}
962
+
963
+ StorageIndex operator[](Index i) const { return i == m_index ? m_value : 0; }
964
+ };
965
+
966
+ /** \internal
967
+ * \sa insert(Index,Index) */
968
+ EIGEN_DEPRECATED EIGEN_DONT_INLINE Scalar& insertUncompressed(Index row, Index col);
969
+
970
+ public:
971
+ /** \internal
972
+ * \sa insert(Index,Index) */
973
+ EIGEN_STRONG_INLINE Scalar& insertBackUncompressed(Index row, Index col) {
974
+ const Index outer = IsRowMajor ? row : col;
975
+ const Index inner = IsRowMajor ? col : row;
976
+
977
+ eigen_assert(!isCompressed());
978
+ eigen_assert(m_innerNonZeros[outer] <= (m_outerIndex[outer + 1] - m_outerIndex[outer]));
979
+
980
+ Index p = m_outerIndex[outer] + m_innerNonZeros[outer]++;
981
+ m_data.index(p) = StorageIndex(inner);
982
+ m_data.value(p) = Scalar(0);
983
+ return m_data.value(p);
984
+ }
891
985
 
892
- eigen_assert(!isCompressed());
893
- eigen_assert(m_innerNonZeros[outer]<=(m_outerIndex[outer+1] - m_outerIndex[outer]));
986
+ protected:
987
+ struct IndexPosPair {
988
+ IndexPosPair(Index a_i, Index a_p) : i(a_i), p(a_p) {}
989
+ Index i;
990
+ Index p;
991
+ };
894
992
 
895
- Index p = m_outerIndex[outer] + m_innerNonZeros[outer]++;
896
- m_data.index(p) = convert_index(inner);
897
- return (m_data.value(p) = Scalar(0));
993
+ /** \internal assign \a diagXpr to the diagonal of \c *this
994
+ * There are different strategies:
995
+ * 1 - if *this is overwritten (Func==assign_op) or *this is empty, then we can work treat *this as a dense vector
996
+ * expression. 2 - otherwise, for each diagonal coeff, 2.a - if it already exists, then we update it, 2.b - if the
997
+ * correct position is at the end of the vector, and there is capacity, push to back 2.b - otherwise, the insertion
998
+ * requires a data move, record insertion locations and handle in a second pass 3 - at the end, if some entries failed
999
+ * to be updated in-place, then we alloc a new buffer, copy each chunk at the right position, and insert the new
1000
+ * elements.
1001
+ */
1002
+ template <typename DiagXpr, typename Func>
1003
+ void assignDiagonal(const DiagXpr diagXpr, const Func& assignFunc) {
1004
+ constexpr StorageIndex kEmptyIndexVal(-1);
1005
+ typedef typename ScalarVector::AlignedMapType ValueMap;
1006
+
1007
+ Index n = diagXpr.size();
1008
+
1009
+ const bool overwrite = internal::is_same<Func, internal::assign_op<Scalar, Scalar>>::value;
1010
+ if (overwrite) {
1011
+ if ((m_outerSize != n) || (m_innerSize != n)) resize(n, n);
898
1012
  }
899
1013
 
900
- private:
901
- static void check_template_parameters()
902
- {
903
- EIGEN_STATIC_ASSERT(NumTraits<StorageIndex>::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE);
904
- EIGEN_STATIC_ASSERT((Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS);
1014
+ if (m_data.size() == 0 || overwrite) {
1015
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
1016
+ m_innerNonZeros = 0;
1017
+ resizeNonZeros(n);
1018
+ ValueMap valueMap(valuePtr(), n);
1019
+ std::iota(m_outerIndex, m_outerIndex + n + 1, StorageIndex(0));
1020
+ std::iota(innerIndexPtr(), innerIndexPtr() + n, StorageIndex(0));
1021
+ valueMap.setZero();
1022
+ internal::call_assignment_no_alias(valueMap, diagXpr, assignFunc);
1023
+ } else {
1024
+ internal::evaluator<DiagXpr> diaEval(diagXpr);
1025
+
1026
+ ei_declare_aligned_stack_constructed_variable(StorageIndex, tmp, n, 0);
1027
+ typename IndexVector::AlignedMapType insertionLocations(tmp, n);
1028
+ insertionLocations.setConstant(kEmptyIndexVal);
1029
+
1030
+ Index deferredInsertions = 0;
1031
+ Index shift = 0;
1032
+
1033
+ for (Index j = 0; j < n; j++) {
1034
+ Index begin = m_outerIndex[j];
1035
+ Index end = isCompressed() ? m_outerIndex[j + 1] : begin + m_innerNonZeros[j];
1036
+ Index capacity = m_outerIndex[j + 1] - end;
1037
+ Index dst = m_data.searchLowerIndex(begin, end, j);
1038
+ // the entry exists: update it now
1039
+ if (dst != end && m_data.index(dst) == StorageIndex(j))
1040
+ assignFunc.assignCoeff(m_data.value(dst), diaEval.coeff(j));
1041
+ // the entry belongs at the back of the vector: push to back
1042
+ else if (dst == end && capacity > 0)
1043
+ assignFunc.assignCoeff(insertBackUncompressed(j, j), diaEval.coeff(j));
1044
+ // the insertion requires a data move, record insertion location and handle in second pass
1045
+ else {
1046
+ insertionLocations.coeffRef(j) = StorageIndex(dst);
1047
+ deferredInsertions++;
1048
+ // if there is no capacity, all vectors to the right of this are shifted
1049
+ if (capacity == 0) shift++;
1050
+ }
1051
+ }
1052
+
1053
+ if (deferredInsertions > 0) {
1054
+ m_data.resize(m_data.size() + shift);
1055
+ Index copyEnd = isCompressed() ? m_outerIndex[m_outerSize]
1056
+ : m_outerIndex[m_outerSize - 1] + m_innerNonZeros[m_outerSize - 1];
1057
+ for (Index j = m_outerSize - 1; deferredInsertions > 0; j--) {
1058
+ Index begin = m_outerIndex[j];
1059
+ Index end = isCompressed() ? m_outerIndex[j + 1] : begin + m_innerNonZeros[j];
1060
+ Index capacity = m_outerIndex[j + 1] - end;
1061
+
1062
+ bool doInsertion = insertionLocations(j) >= 0;
1063
+ bool breakUpCopy = doInsertion && (capacity > 0);
1064
+ // break up copy for sorted insertion into inactive nonzeros
1065
+ // optionally, add another criterium, i.e. 'breakUpCopy || (capacity > threhsold)'
1066
+ // where `threshold >= 0` to skip inactive nonzeros in each vector
1067
+ // this reduces the total number of copied elements, but requires more moveChunk calls
1068
+ if (breakUpCopy) {
1069
+ Index copyBegin = m_outerIndex[j + 1];
1070
+ Index to = copyBegin + shift;
1071
+ Index chunkSize = copyEnd - copyBegin;
1072
+ m_data.moveChunk(copyBegin, to, chunkSize);
1073
+ copyEnd = end;
1074
+ }
1075
+
1076
+ m_outerIndex[j + 1] += shift;
1077
+
1078
+ if (doInsertion) {
1079
+ // if there is capacity, shift into the inactive nonzeros
1080
+ if (capacity > 0) shift++;
1081
+ Index copyBegin = insertionLocations(j);
1082
+ Index to = copyBegin + shift;
1083
+ Index chunkSize = copyEnd - copyBegin;
1084
+ m_data.moveChunk(copyBegin, to, chunkSize);
1085
+ Index dst = to - 1;
1086
+ m_data.index(dst) = StorageIndex(j);
1087
+ m_data.value(dst) = Scalar(0);
1088
+ assignFunc.assignCoeff(m_data.value(dst), diaEval.coeff(j));
1089
+ if (!isCompressed()) m_innerNonZeros[j]++;
1090
+ shift--;
1091
+ deferredInsertions--;
1092
+ copyEnd = copyBegin;
1093
+ }
1094
+ }
1095
+ }
1096
+ eigen_assert((shift == 0) && (deferredInsertions == 0));
1097
+ }
905
1098
  }
906
1099
 
1100
+ /* These functions are used to avoid a redundant binary search operation in functions such as coeffRef() and assume
1101
+ * `dst` is the appropriate sorted insertion point */
1102
+ EIGEN_STRONG_INLINE Scalar& insertAtByOuterInner(Index outer, Index inner, Index dst);
1103
+ Scalar& insertCompressedAtByOuterInner(Index outer, Index inner, Index dst);
1104
+ Scalar& insertUncompressedAtByOuterInner(Index outer, Index inner, Index dst);
1105
+
1106
+ private:
1107
+ EIGEN_STATIC_ASSERT(NumTraits<StorageIndex>::IsSigned, THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE)
1108
+ EIGEN_STATIC_ASSERT((Options & (ColMajor | RowMajor)) == Options, INVALID_MATRIX_TEMPLATE_PARAMETERS)
1109
+
907
1110
  struct default_prunning_func {
908
1111
  default_prunning_func(const Scalar& ref, const RealScalar& eps) : reference(ref), epsilon(eps) {}
909
- inline bool operator() (const Index&, const Index&, const Scalar& value) const
910
- {
1112
+ inline bool operator()(const Index&, const Index&, const Scalar& value) const {
911
1113
  return !internal::isMuchSmallerThan(value, reference, epsilon);
912
1114
  }
913
1115
  Scalar reference;
@@ -917,56 +1119,190 @@ private:
917
1119
 
918
1120
  namespace internal {
919
1121
 
920
- template<typename InputIterator, typename SparseMatrixType, typename DupFunctor>
921
- void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat, DupFunctor dup_func)
922
- {
923
- enum { IsRowMajor = SparseMatrixType::IsRowMajor };
924
- typedef typename SparseMatrixType::Scalar Scalar;
925
- typedef typename SparseMatrixType::StorageIndex StorageIndex;
926
- SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor,StorageIndex> trMat(mat.rows(),mat.cols());
927
-
928
- if(begin!=end)
929
- {
930
- // pass 1: count the nnz per inner-vector
931
- typename SparseMatrixType::IndexVector wi(trMat.outerSize());
932
- wi.setZero();
933
- for(InputIterator it(begin); it!=end; ++it)
934
- {
935
- eigen_assert(it->row()>=0 && it->row()<mat.rows() && it->col()>=0 && it->col()<mat.cols());
936
- wi(IsRowMajor ? it->col() : it->row())++;
1122
+ // Creates a compressed sparse matrix from a range of unsorted triplets
1123
+ // Requires temporary storage to handle duplicate entries
1124
+ template <typename InputIterator, typename SparseMatrixType, typename DupFunctor>
1125
+ void set_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat,
1126
+ DupFunctor dup_func) {
1127
+ constexpr bool IsRowMajor = SparseMatrixType::IsRowMajor;
1128
+ using StorageIndex = typename SparseMatrixType::StorageIndex;
1129
+ using IndexMap = typename VectorX<StorageIndex>::AlignedMapType;
1130
+ using TransposedSparseMatrix =
1131
+ SparseMatrix<typename SparseMatrixType::Scalar, IsRowMajor ? ColMajor : RowMajor, StorageIndex>;
1132
+
1133
+ if (begin == end) {
1134
+ // Clear out existing data (if any).
1135
+ mat.setZero();
1136
+ return;
1137
+ }
1138
+
1139
+ // There are two strategies to consider for constructing a matrix from unordered triplets:
1140
+ // A) construct the 'mat' in its native storage order and sort in-place (less memory); or,
1141
+ // B) construct the transposed matrix and use an implicit sort upon assignment to `mat` (less time).
1142
+ // This routine uses B) for faster execution time.
1143
+ TransposedSparseMatrix trmat(mat.rows(), mat.cols());
1144
+
1145
+ // scan triplets to determine allocation size before constructing matrix
1146
+ Index nonZeros = 0;
1147
+ for (InputIterator it(begin); it != end; ++it) {
1148
+ eigen_assert(it->row() >= 0 && it->row() < mat.rows() && it->col() >= 0 && it->col() < mat.cols());
1149
+ StorageIndex j = convert_index<StorageIndex>(IsRowMajor ? it->col() : it->row());
1150
+ if (nonZeros == NumTraits<StorageIndex>::highest()) internal::throw_std_bad_alloc();
1151
+ trmat.outerIndexPtr()[j + 1]++;
1152
+ nonZeros++;
1153
+ }
1154
+
1155
+ std::partial_sum(trmat.outerIndexPtr(), trmat.outerIndexPtr() + trmat.outerSize() + 1, trmat.outerIndexPtr());
1156
+ eigen_assert(nonZeros == trmat.outerIndexPtr()[trmat.outerSize()]);
1157
+ trmat.resizeNonZeros(nonZeros);
1158
+
1159
+ // construct temporary array to track insertions (outersize) and collapse duplicates (innersize)
1160
+ ei_declare_aligned_stack_constructed_variable(StorageIndex, tmp, numext::maxi(mat.innerSize(), mat.outerSize()), 0);
1161
+ smart_copy(trmat.outerIndexPtr(), trmat.outerIndexPtr() + trmat.outerSize(), tmp);
1162
+
1163
+ // push triplets to back of each vector
1164
+ for (InputIterator it(begin); it != end; ++it) {
1165
+ StorageIndex j = convert_index<StorageIndex>(IsRowMajor ? it->col() : it->row());
1166
+ StorageIndex i = convert_index<StorageIndex>(IsRowMajor ? it->row() : it->col());
1167
+ StorageIndex k = tmp[j];
1168
+ trmat.data().index(k) = i;
1169
+ trmat.data().value(k) = it->value();
1170
+ tmp[j]++;
1171
+ }
1172
+
1173
+ IndexMap wi(tmp, trmat.innerSize());
1174
+ trmat.collapseDuplicates(wi, dup_func);
1175
+ // implicit sorting
1176
+ mat = trmat;
1177
+ }
1178
+
1179
+ // Creates a compressed sparse matrix from a sorted range of triplets
1180
+ template <typename InputIterator, typename SparseMatrixType, typename DupFunctor>
1181
+ void set_from_triplets_sorted(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat,
1182
+ DupFunctor dup_func) {
1183
+ constexpr bool IsRowMajor = SparseMatrixType::IsRowMajor;
1184
+ using StorageIndex = typename SparseMatrixType::StorageIndex;
1185
+
1186
+ if (begin == end) return;
1187
+
1188
+ constexpr StorageIndex kEmptyIndexValue(-1);
1189
+ // deallocate inner nonzeros if present and zero outerIndexPtr
1190
+ mat.resize(mat.rows(), mat.cols());
1191
+ // use outer indices to count non zero entries (excluding duplicate entries)
1192
+ StorageIndex previous_j = kEmptyIndexValue;
1193
+ StorageIndex previous_i = kEmptyIndexValue;
1194
+ // scan triplets to determine allocation size before constructing matrix
1195
+ Index nonZeros = 0;
1196
+ for (InputIterator it(begin); it != end; ++it) {
1197
+ eigen_assert(it->row() >= 0 && it->row() < mat.rows() && it->col() >= 0 && it->col() < mat.cols());
1198
+ StorageIndex j = convert_index<StorageIndex>(IsRowMajor ? it->row() : it->col());
1199
+ StorageIndex i = convert_index<StorageIndex>(IsRowMajor ? it->col() : it->row());
1200
+ eigen_assert(j > previous_j || (j == previous_j && i >= previous_i));
1201
+ // identify duplicates by examining previous location
1202
+ bool duplicate = (previous_j == j) && (previous_i == i);
1203
+ if (!duplicate) {
1204
+ if (nonZeros == NumTraits<StorageIndex>::highest()) internal::throw_std_bad_alloc();
1205
+ nonZeros++;
1206
+ mat.outerIndexPtr()[j + 1]++;
1207
+ previous_j = j;
1208
+ previous_i = i;
937
1209
  }
1210
+ }
938
1211
 
939
- // pass 2: insert all the elements into trMat
940
- trMat.reserve(wi);
941
- for(InputIterator it(begin); it!=end; ++it)
942
- trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
1212
+ // finalize outer indices and allocate memory
1213
+ std::partial_sum(mat.outerIndexPtr(), mat.outerIndexPtr() + mat.outerSize() + 1, mat.outerIndexPtr());
1214
+ eigen_assert(nonZeros == mat.outerIndexPtr()[mat.outerSize()]);
1215
+ mat.resizeNonZeros(nonZeros);
1216
+
1217
+ previous_i = kEmptyIndexValue;
1218
+ previous_j = kEmptyIndexValue;
1219
+ Index back = 0;
1220
+ for (InputIterator it(begin); it != end; ++it) {
1221
+ StorageIndex j = convert_index<StorageIndex>(IsRowMajor ? it->row() : it->col());
1222
+ StorageIndex i = convert_index<StorageIndex>(IsRowMajor ? it->col() : it->row());
1223
+ bool duplicate = (previous_j == j) && (previous_i == i);
1224
+ if (duplicate) {
1225
+ mat.data().value(back - 1) = dup_func(mat.data().value(back - 1), it->value());
1226
+ } else {
1227
+ // push triplets to back
1228
+ mat.data().index(back) = i;
1229
+ mat.data().value(back) = it->value();
1230
+ previous_j = j;
1231
+ previous_i = i;
1232
+ back++;
1233
+ }
1234
+ }
1235
+ eigen_assert(back == nonZeros);
1236
+ // matrix is finalized
1237
+ }
943
1238
 
944
- // pass 3:
945
- trMat.collapseDuplicates(dup_func);
1239
+ // thin wrapper around a generic binary functor to use the sparse disjunction evaluator instead of the default
1240
+ // "arithmetic" evaluator
1241
+ template <typename DupFunctor, typename LhsScalar, typename RhsScalar = LhsScalar>
1242
+ struct scalar_disjunction_op {
1243
+ using result_type = typename result_of<DupFunctor(LhsScalar, RhsScalar)>::type;
1244
+ scalar_disjunction_op(const DupFunctor& op) : m_functor(op) {}
1245
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator()(const LhsScalar& a, const RhsScalar& b) const {
1246
+ return m_functor(a, b);
946
1247
  }
1248
+ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const DupFunctor& functor() const { return m_functor; }
1249
+ const DupFunctor& m_functor;
1250
+ };
947
1251
 
948
- // pass 4: transposed copy -> implicit sorting
949
- mat = trMat;
1252
+ template <typename DupFunctor, typename LhsScalar, typename RhsScalar>
1253
+ struct functor_traits<scalar_disjunction_op<DupFunctor, LhsScalar, RhsScalar>> : public functor_traits<DupFunctor> {};
1254
+
1255
+ // Creates a compressed sparse matrix from its existing entries and those from an unsorted range of triplets
1256
+ template <typename InputIterator, typename SparseMatrixType, typename DupFunctor>
1257
+ void insert_from_triplets(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat,
1258
+ DupFunctor dup_func) {
1259
+ using Scalar = typename SparseMatrixType::Scalar;
1260
+ using SrcXprType =
1261
+ CwiseBinaryOp<scalar_disjunction_op<DupFunctor, Scalar>, const SparseMatrixType, const SparseMatrixType>;
1262
+
1263
+ // set_from_triplets is necessary to sort the inner indices and remove the duplicate entries
1264
+ SparseMatrixType trips(mat.rows(), mat.cols());
1265
+ set_from_triplets(begin, end, trips, dup_func);
1266
+
1267
+ SrcXprType src = mat.binaryExpr(trips, scalar_disjunction_op<DupFunctor, Scalar>(dup_func));
1268
+ // the sparse assignment procedure creates a temporary matrix and swaps the final result
1269
+ assign_sparse_to_sparse<SparseMatrixType, SrcXprType>(mat, src);
950
1270
  }
951
1271
 
1272
+ // Creates a compressed sparse matrix from its existing entries and those from an sorted range of triplets
1273
+ template <typename InputIterator, typename SparseMatrixType, typename DupFunctor>
1274
+ void insert_from_triplets_sorted(const InputIterator& begin, const InputIterator& end, SparseMatrixType& mat,
1275
+ DupFunctor dup_func) {
1276
+ using Scalar = typename SparseMatrixType::Scalar;
1277
+ using SrcXprType =
1278
+ CwiseBinaryOp<scalar_disjunction_op<DupFunctor, Scalar>, const SparseMatrixType, const SparseMatrixType>;
1279
+
1280
+ // TODO: process triplets without making a copy
1281
+ SparseMatrixType trips(mat.rows(), mat.cols());
1282
+ set_from_triplets_sorted(begin, end, trips, dup_func);
1283
+
1284
+ SrcXprType src = mat.binaryExpr(trips, scalar_disjunction_op<DupFunctor, Scalar>(dup_func));
1285
+ // the sparse assignment procedure creates a temporary matrix and swaps the final result
1286
+ assign_sparse_to_sparse<SparseMatrixType, SrcXprType>(mat, src);
952
1287
  }
953
1288
 
1289
+ } // namespace internal
954
1290
 
955
- /** Fill the matrix \c *this with the list of \em triplets defined by the iterator range \a begin - \a end.
1291
+ /** Fill the matrix \c *this with the list of \em triplets defined in the half-open range from \a begin to \a end.
956
1292
  *
957
1293
  * A \em triplet is a tuple (i,j,value) defining a non-zero element.
958
- * The input list of triplets does not have to be sorted, and can contains duplicated elements.
1294
+ * The input list of triplets does not have to be sorted, and may contain duplicated elements.
959
1295
  * In any case, the result is a \b sorted and \b compressed sparse matrix where the duplicates have been summed up.
960
1296
  * This is a \em O(n) operation, with \em n the number of triplet elements.
961
- * The initial contents of \c *this is destroyed.
1297
+ * The initial contents of \c *this are destroyed.
962
1298
  * The matrix \c *this must be properly resized beforehand using the SparseMatrix(Index,Index) constructor,
963
1299
  * or the resize(Index,Index) method. The sizes are not extracted from the triplet list.
964
1300
  *
965
1301
  * The \a InputIterators value_type must provide the following interface:
966
1302
  * \code
967
1303
  * Scalar value() const; // the value
968
- * Scalar row() const; // the row index i
969
- * Scalar col() const; // the column index j
1304
+ * IndexType row() const; // the row index i
1305
+ * IndexType col() const; // the column index j
970
1306
  * \endcode
971
1307
  * See for instance the Eigen::Triplet template class.
972
1308
  *
@@ -974,7 +1310,7 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa
974
1310
  * \code
975
1311
  typedef Triplet<double> T;
976
1312
  std::vector<T> tripletList;
977
- triplets.reserve(estimation_of_entries);
1313
+ tripletList.reserve(estimation_of_entries);
978
1314
  for(...)
979
1315
  {
980
1316
  // ...
@@ -987,113 +1323,239 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa
987
1323
  *
988
1324
  * \warning The list of triplets is read multiple times (at least twice). Therefore, it is not recommended to define
989
1325
  * an abstract iterator over a complex data-structure that would be expensive to evaluate. The triplets should rather
990
- * be explicitely stored into a std::vector for instance.
1326
+ * be explicitly stored into a std::vector for instance.
991
1327
  */
992
- template<typename Scalar, int _Options, typename _StorageIndex>
993
- template<typename InputIterators>
994
- void SparseMatrix<Scalar,_Options,_StorageIndex>::setFromTriplets(const InputIterators& begin, const InputIterators& end)
995
- {
996
- internal::set_from_triplets<InputIterators, SparseMatrix<Scalar,_Options,_StorageIndex> >(begin, end, *this, internal::scalar_sum_op<Scalar,Scalar>());
1328
+ template <typename Scalar, int Options_, typename StorageIndex_>
1329
+ template <typename InputIterators>
1330
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::setFromTriplets(const InputIterators& begin,
1331
+ const InputIterators& end) {
1332
+ internal::set_from_triplets<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>>(
1333
+ begin, end, *this, internal::scalar_sum_op<Scalar, Scalar>());
997
1334
  }
998
1335
 
999
1336
  /** The same as setFromTriplets but when duplicates are met the functor \a dup_func is applied:
1337
+ * \code
1338
+ * value = dup_func(OldValue, NewValue)
1339
+ * \endcode
1340
+ * Here is a C++11 example keeping the latest entry only:
1341
+ * \code
1342
+ * mat.setFromTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });
1343
+ * \endcode
1344
+ */
1345
+ template <typename Scalar, int Options_, typename StorageIndex_>
1346
+ template <typename InputIterators, typename DupFunctor>
1347
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::setFromTriplets(const InputIterators& begin,
1348
+ const InputIterators& end, DupFunctor dup_func) {
1349
+ internal::set_from_triplets<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>, DupFunctor>(
1350
+ begin, end, *this, dup_func);
1351
+ }
1352
+
1353
+ /** The same as setFromTriplets but triplets are assumed to be pre-sorted. This is faster and requires less temporary
1354
+ * storage. Two triplets `a` and `b` are appropriately ordered if: \code ColMajor: ((a.col() != b.col()) ? (a.col() <
1355
+ * b.col()) : (a.row() < b.row()) RowMajor: ((a.row() != b.row()) ? (a.row() < b.row()) : (a.col() < b.col()) \endcode
1356
+ */
1357
+ template <typename Scalar, int Options_, typename StorageIndex_>
1358
+ template <typename InputIterators>
1359
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::setFromSortedTriplets(const InputIterators& begin,
1360
+ const InputIterators& end) {
1361
+ internal::set_from_triplets_sorted<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>>(
1362
+ begin, end, *this, internal::scalar_sum_op<Scalar, Scalar>());
1363
+ }
1364
+
1365
+ /** The same as setFromSortedTriplets but when duplicates are met the functor \a dup_func is applied:
1366
+ * \code
1367
+ * value = dup_func(OldValue, NewValue)
1368
+ * \endcode
1369
+ * Here is a C++11 example keeping the latest entry only:
1370
+ * \code
1371
+ * mat.setFromSortedTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });
1372
+ * \endcode
1373
+ */
1374
+ template <typename Scalar, int Options_, typename StorageIndex_>
1375
+ template <typename InputIterators, typename DupFunctor>
1376
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::setFromSortedTriplets(const InputIterators& begin,
1377
+ const InputIterators& end,
1378
+ DupFunctor dup_func) {
1379
+ internal::set_from_triplets_sorted<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>, DupFunctor>(
1380
+ begin, end, *this, dup_func);
1381
+ }
1382
+
1383
+ /** Insert a batch of elements into the matrix \c *this with the list of \em triplets defined in the half-open range
1384
+ from \a begin to \a end.
1385
+ *
1386
+ * A \em triplet is a tuple (i,j,value) defining a non-zero element.
1387
+ * The input list of triplets does not have to be sorted, and may contain duplicated elements.
1388
+ * In any case, the result is a \b sorted and \b compressed sparse matrix where the duplicates have been summed up.
1389
+ * This is a \em O(n) operation, with \em n the number of triplet elements.
1390
+ * The initial contents of \c *this are preserved (except for the summation of duplicate elements).
1391
+ * The matrix \c *this must be properly sized beforehand. The sizes are not extracted from the triplet list.
1392
+ *
1393
+ * The \a InputIterators value_type must provide the following interface:
1000
1394
  * \code
1001
- * value = dup_func(OldValue, NewValue)
1002
- * \endcode
1003
- * Here is a C++11 example keeping the latest entry only:
1395
+ * Scalar value() const; // the value
1396
+ * IndexType row() const; // the row index i
1397
+ * IndexType col() const; // the column index j
1398
+ * \endcode
1399
+ * See for instance the Eigen::Triplet template class.
1400
+ *
1401
+ * Here is a typical usage example:
1004
1402
  * \code
1005
- * mat.setFromTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });
1403
+ SparseMatrixType m(rows,cols); // m contains nonzero entries
1404
+ typedef Triplet<double> T;
1405
+ std::vector<T> tripletList;
1406
+ tripletList.reserve(estimation_of_entries);
1407
+ for(...)
1408
+ {
1409
+ // ...
1410
+ tripletList.push_back(T(i,j,v_ij));
1411
+ }
1412
+
1413
+ m.insertFromTriplets(tripletList.begin(), tripletList.end());
1414
+ // m is ready to go!
1006
1415
  * \endcode
1416
+ *
1417
+ * \warning The list of triplets is read multiple times (at least twice). Therefore, it is not recommended to define
1418
+ * an abstract iterator over a complex data-structure that would be expensive to evaluate. The triplets should rather
1419
+ * be explicitly stored into a std::vector for instance.
1007
1420
  */
1008
- template<typename Scalar, int _Options, typename _StorageIndex>
1009
- template<typename InputIterators,typename DupFunctor>
1010
- void SparseMatrix<Scalar,_Options,_StorageIndex>::setFromTriplets(const InputIterators& begin, const InputIterators& end, DupFunctor dup_func)
1011
- {
1012
- internal::set_from_triplets<InputIterators, SparseMatrix<Scalar,_Options,_StorageIndex>, DupFunctor>(begin, end, *this, dup_func);
1421
+ template <typename Scalar, int Options_, typename StorageIndex_>
1422
+ template <typename InputIterators>
1423
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::insertFromTriplets(const InputIterators& begin,
1424
+ const InputIterators& end) {
1425
+ internal::insert_from_triplets<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>>(
1426
+ begin, end, *this, internal::scalar_sum_op<Scalar, Scalar>());
1427
+ }
1428
+
1429
+ /** The same as insertFromTriplets but when duplicates are met the functor \a dup_func is applied:
1430
+ * \code
1431
+ * value = dup_func(OldValue, NewValue)
1432
+ * \endcode
1433
+ * Here is a C++11 example keeping the latest entry only:
1434
+ * \code
1435
+ * mat.insertFromTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });
1436
+ * \endcode
1437
+ */
1438
+ template <typename Scalar, int Options_, typename StorageIndex_>
1439
+ template <typename InputIterators, typename DupFunctor>
1440
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::insertFromTriplets(const InputIterators& begin,
1441
+ const InputIterators& end, DupFunctor dup_func) {
1442
+ internal::insert_from_triplets<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>, DupFunctor>(
1443
+ begin, end, *this, dup_func);
1444
+ }
1445
+
1446
+ /** The same as insertFromTriplets but triplets are assumed to be pre-sorted. This is faster and requires less temporary
1447
+ * storage. Two triplets `a` and `b` are appropriately ordered if: \code ColMajor: ((a.col() != b.col()) ? (a.col() <
1448
+ * b.col()) : (a.row() < b.row()) RowMajor: ((a.row() != b.row()) ? (a.row() < b.row()) : (a.col() < b.col()) \endcode
1449
+ */
1450
+ template <typename Scalar, int Options_, typename StorageIndex_>
1451
+ template <typename InputIterators>
1452
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::insertFromSortedTriplets(const InputIterators& begin,
1453
+ const InputIterators& end) {
1454
+ internal::insert_from_triplets_sorted<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>>(
1455
+ begin, end, *this, internal::scalar_sum_op<Scalar, Scalar>());
1456
+ }
1457
+
1458
+ /** The same as insertFromSortedTriplets but when duplicates are met the functor \a dup_func is applied:
1459
+ * \code
1460
+ * value = dup_func(OldValue, NewValue)
1461
+ * \endcode
1462
+ * Here is a C++11 example keeping the latest entry only:
1463
+ * \code
1464
+ * mat.insertFromSortedTriplets(triplets.begin(), triplets.end(), [] (const Scalar&,const Scalar &b) { return b; });
1465
+ * \endcode
1466
+ */
1467
+ template <typename Scalar, int Options_, typename StorageIndex_>
1468
+ template <typename InputIterators, typename DupFunctor>
1469
+ void SparseMatrix<Scalar, Options_, StorageIndex_>::insertFromSortedTriplets(const InputIterators& begin,
1470
+ const InputIterators& end,
1471
+ DupFunctor dup_func) {
1472
+ internal::insert_from_triplets_sorted<InputIterators, SparseMatrix<Scalar, Options_, StorageIndex_>, DupFunctor>(
1473
+ begin, end, *this, dup_func);
1013
1474
  }
1014
1475
 
1015
1476
  /** \internal */
1016
- template<typename Scalar, int _Options, typename _StorageIndex>
1017
- template<typename DupFunctor>
1018
- void SparseMatrix<Scalar,_Options,_StorageIndex>::collapseDuplicates(DupFunctor dup_func)
1019
- {
1020
- eigen_assert(!isCompressed());
1021
- // TODO, in practice we should be able to use m_innerNonZeros for that task
1022
- IndexVector wi(innerSize());
1023
- wi.fill(-1);
1477
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1478
+ template <typename Derived, typename DupFunctor>
1479
+ void SparseMatrix<Scalar_, Options_, StorageIndex_>::collapseDuplicates(DenseBase<Derived>& wi, DupFunctor dup_func) {
1480
+ // removes duplicate entries and compresses the matrix
1481
+ // the excess allocated memory is not released
1482
+ // the inner indices do not need to be sorted, nor is the matrix returned in a sorted state
1483
+ eigen_assert(wi.size() == m_innerSize);
1484
+ constexpr StorageIndex kEmptyIndexValue(-1);
1485
+ wi.setConstant(kEmptyIndexValue);
1024
1486
  StorageIndex count = 0;
1487
+ const bool is_compressed = isCompressed();
1025
1488
  // for each inner-vector, wi[inner_index] will hold the position of first element into the index/value buffers
1026
- for(Index j=0; j<outerSize(); ++j)
1027
- {
1028
- StorageIndex start = count;
1029
- Index oldEnd = m_outerIndex[j]+m_innerNonZeros[j];
1030
- for(Index k=m_outerIndex[j]; k<oldEnd; ++k)
1031
- {
1032
- Index i = m_data.index(k);
1033
- if(wi(i)>=start)
1034
- {
1035
- // we already meet this entry => accumulate it
1489
+ for (Index j = 0; j < m_outerSize; ++j) {
1490
+ const StorageIndex newBegin = count;
1491
+ const StorageIndex end = is_compressed ? m_outerIndex[j + 1] : m_outerIndex[j] + m_innerNonZeros[j];
1492
+ for (StorageIndex k = m_outerIndex[j]; k < end; ++k) {
1493
+ StorageIndex i = m_data.index(k);
1494
+ if (wi(i) >= newBegin) {
1495
+ // entry at k is a duplicate
1496
+ // accumulate it into the primary entry located at wi(i)
1036
1497
  m_data.value(wi(i)) = dup_func(m_data.value(wi(i)), m_data.value(k));
1037
- }
1038
- else
1039
- {
1498
+ } else {
1499
+ // k is the primary entry in j with inner index i
1500
+ // shift it to the left and record its location at wi(i)
1501
+ m_data.index(count) = i;
1040
1502
  m_data.value(count) = m_data.value(k);
1041
- m_data.index(count) = m_data.index(k);
1042
1503
  wi(i) = count;
1043
1504
  ++count;
1044
1505
  }
1045
1506
  }
1046
- m_outerIndex[j] = start;
1507
+ m_outerIndex[j] = newBegin;
1047
1508
  }
1048
1509
  m_outerIndex[m_outerSize] = count;
1510
+ m_data.resize(count);
1049
1511
 
1050
- // turn the matrix into compressed form
1051
- std::free(m_innerNonZeros);
1512
+ // turn the matrix into compressed form (if it is not already)
1513
+ internal::conditional_aligned_delete_auto<StorageIndex, true>(m_innerNonZeros, m_outerSize);
1052
1514
  m_innerNonZeros = 0;
1053
- m_data.resize(m_outerIndex[m_outerSize]);
1054
1515
  }
1055
1516
 
1056
- template<typename Scalar, int _Options, typename _StorageIndex>
1057
- template<typename OtherDerived>
1058
- EIGEN_DONT_INLINE SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scalar,_Options,_StorageIndex>::operator=(const SparseMatrixBase<OtherDerived>& other)
1059
- {
1060
- EIGEN_STATIC_ASSERT((internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
1061
- YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
1517
+ /** \internal */
1518
+ template <typename Scalar, int Options_, typename StorageIndex_>
1519
+ template <typename OtherDerived>
1520
+ EIGEN_DONT_INLINE SparseMatrix<Scalar, Options_, StorageIndex_>&
1521
+ SparseMatrix<Scalar, Options_, StorageIndex_>::operator=(const SparseMatrixBase<OtherDerived>& other) {
1522
+ EIGEN_STATIC_ASSERT(
1523
+ (internal::is_same<Scalar, typename OtherDerived::Scalar>::value),
1524
+ YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
1525
+
1526
+ #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
1527
+ EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
1528
+ #endif
1062
1529
 
1063
- #ifdef EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
1064
- EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN
1065
- #endif
1066
-
1067
1530
  const bool needToTranspose = (Flags & RowMajorBit) != (internal::evaluator<OtherDerived>::Flags & RowMajorBit);
1068
- if (needToTranspose)
1069
- {
1070
- #ifdef EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN
1071
- EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN
1072
- #endif
1531
+ if (needToTranspose) {
1532
+ #ifdef EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN
1533
+ EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN
1534
+ #endif
1073
1535
  // two passes algorithm:
1074
1536
  // 1 - compute the number of coeffs per dest inner vector
1075
1537
  // 2 - do the actual copy/eval
1076
1538
  // Since each coeff of the rhs has to be evaluated twice, let's evaluate it if needed
1077
- typedef typename internal::nested_eval<OtherDerived,2,typename internal::plain_matrix_type<OtherDerived>::type >::type OtherCopy;
1078
- typedef typename internal::remove_all<OtherCopy>::type _OtherCopy;
1079
- typedef internal::evaluator<_OtherCopy> OtherCopyEval;
1539
+ typedef
1540
+ typename internal::nested_eval<OtherDerived, 2, typename internal::plain_matrix_type<OtherDerived>::type>::type
1541
+ OtherCopy;
1542
+ typedef internal::remove_all_t<OtherCopy> OtherCopy_;
1543
+ typedef internal::evaluator<OtherCopy_> OtherCopyEval;
1080
1544
  OtherCopy otherCopy(other.derived());
1081
1545
  OtherCopyEval otherCopyEval(otherCopy);
1082
1546
 
1083
- SparseMatrix dest(other.rows(),other.cols());
1084
- Eigen::Map<IndexVector> (dest.m_outerIndex,dest.outerSize()).setZero();
1547
+ SparseMatrix dest(other.rows(), other.cols());
1548
+ Eigen::Map<IndexVector>(dest.m_outerIndex, dest.outerSize()).setZero();
1085
1549
 
1086
1550
  // pass 1
1087
1551
  // FIXME the above copy could be merged with that pass
1088
- for (Index j=0; j<otherCopy.outerSize(); ++j)
1089
- for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it)
1090
- ++dest.m_outerIndex[it.index()];
1552
+ for (Index j = 0; j < otherCopy.outerSize(); ++j)
1553
+ for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it) ++dest.m_outerIndex[it.index()];
1091
1554
 
1092
1555
  // prefix sum
1093
1556
  StorageIndex count = 0;
1094
1557
  IndexVector positions(dest.outerSize());
1095
- for (Index j=0; j<dest.outerSize(); ++j)
1096
- {
1558
+ for (Index j = 0; j < dest.outerSize(); ++j) {
1097
1559
  StorageIndex tmp = dest.m_outerIndex[j];
1098
1560
  dest.m_outerIndex[j] = count;
1099
1561
  positions[j] = count;
@@ -1103,10 +1565,8 @@ EIGEN_DONT_INLINE SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scal
1103
1565
  // alloc
1104
1566
  dest.m_data.resize(count);
1105
1567
  // pass 2
1106
- for (StorageIndex j=0; j<otherCopy.outerSize(); ++j)
1107
- {
1108
- for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it)
1109
- {
1568
+ for (StorageIndex j = 0; j < otherCopy.outerSize(); ++j) {
1569
+ for (typename OtherCopyEval::InnerIterator it(otherCopyEval, j); it; ++it) {
1110
1570
  Index pos = positions[it.index()]++;
1111
1571
  dest.m_data.index(pos) = j;
1112
1572
  dest.m_data.value(pos) = it.value();
@@ -1114,11 +1574,8 @@ EIGEN_DONT_INLINE SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scal
1114
1574
  }
1115
1575
  this->swap(dest);
1116
1576
  return *this;
1117
- }
1118
- else
1119
- {
1120
- if(other.isRValue())
1121
- {
1577
+ } else {
1578
+ if (other.isRValue()) {
1122
1579
  initAssignment(other.derived());
1123
1580
  }
1124
1581
  // there is no special optimization
@@ -1126,279 +1583,294 @@ EIGEN_DONT_INLINE SparseMatrix<Scalar,_Options,_StorageIndex>& SparseMatrix<Scal
1126
1583
  }
1127
1584
  }
1128
1585
 
1129
- template<typename _Scalar, int _Options, typename _StorageIndex>
1130
- typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insert(Index row, Index col)
1131
- {
1132
- eigen_assert(row>=0 && row<rows() && col>=0 && col<cols());
1133
-
1134
- const Index outer = IsRowMajor ? row : col;
1135
- const Index inner = IsRowMajor ? col : row;
1136
-
1137
- if(isCompressed())
1138
- {
1139
- if(nonZeros()==0)
1140
- {
1141
- // reserve space if not already done
1142
- if(m_data.allocatedSize()==0)
1143
- m_data.reserve(2*m_innerSize);
1144
-
1145
- // turn the matrix into non-compressed mode
1146
- m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex)));
1147
- if(!m_innerNonZeros) internal::throw_std_bad_alloc();
1148
-
1149
- memset(m_innerNonZeros, 0, (m_outerSize)*sizeof(StorageIndex));
1150
-
1151
- // pack all inner-vectors to the end of the pre-allocated space
1152
- // and allocate the entire free-space to the first inner-vector
1153
- StorageIndex end = convert_index(m_data.allocatedSize());
1154
- for(Index j=1; j<=m_outerSize; ++j)
1155
- m_outerIndex[j] = end;
1156
- }
1157
- else
1158
- {
1159
- // turn the matrix into non-compressed mode
1160
- m_innerNonZeros = static_cast<StorageIndex*>(std::malloc(m_outerSize * sizeof(StorageIndex)));
1161
- if(!m_innerNonZeros) internal::throw_std_bad_alloc();
1162
- for(Index j=0; j<m_outerSize; ++j)
1163
- m_innerNonZeros[j] = m_outerIndex[j+1]-m_outerIndex[j];
1586
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1587
+ inline typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1588
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insert(Index row, Index col) {
1589
+ return insertByOuterInner(IsRowMajor ? row : col, IsRowMajor ? col : row);
1590
+ }
1591
+
1592
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1593
+ EIGEN_STRONG_INLINE typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1594
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insertAtByOuterInner(Index outer, Index inner, Index dst) {
1595
+ // random insertion into compressed matrix is very slow
1596
+ uncompress();
1597
+ return insertUncompressedAtByOuterInner(outer, inner, dst);
1598
+ }
1599
+
1600
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1601
+ EIGEN_DEPRECATED EIGEN_DONT_INLINE typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1602
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insertUncompressed(Index row, Index col) {
1603
+ eigen_assert(!isCompressed());
1604
+ Index outer = IsRowMajor ? row : col;
1605
+ Index inner = IsRowMajor ? col : row;
1606
+ Index start = m_outerIndex[outer];
1607
+ Index end = start + m_innerNonZeros[outer];
1608
+ Index dst = start == end ? end : m_data.searchLowerIndex(start, end, inner);
1609
+ if (dst == end) {
1610
+ Index capacity = m_outerIndex[outer + 1] - end;
1611
+ if (capacity > 0) {
1612
+ // implies uncompressed: push to back of vector
1613
+ m_innerNonZeros[outer]++;
1614
+ m_data.index(end) = StorageIndex(inner);
1615
+ m_data.value(end) = Scalar(0);
1616
+ return m_data.value(end);
1164
1617
  }
1165
1618
  }
1166
-
1167
- // check whether we can do a fast "push back" insertion
1168
- Index data_end = m_data.allocatedSize();
1169
-
1170
- // First case: we are filling a new inner vector which is packed at the end.
1171
- // We assume that all remaining inner-vectors are also empty and packed to the end.
1172
- if(m_outerIndex[outer]==data_end)
1173
- {
1174
- eigen_internal_assert(m_innerNonZeros[outer]==0);
1175
-
1176
- // pack previous empty inner-vectors to end of the used-space
1177
- // and allocate the entire free-space to the current inner-vector.
1178
- StorageIndex p = convert_index(m_data.size());
1179
- Index j = outer;
1180
- while(j>=0 && m_innerNonZeros[j]==0)
1181
- m_outerIndex[j--] = p;
1182
-
1183
- // push back the new element
1184
- ++m_innerNonZeros[outer];
1185
- m_data.append(Scalar(0), inner);
1186
-
1187
- // check for reallocation
1188
- if(data_end != m_data.allocatedSize())
1189
- {
1190
- // m_data has been reallocated
1191
- // -> move remaining inner-vectors back to the end of the free-space
1192
- // so that the entire free-space is allocated to the current inner-vector.
1193
- eigen_internal_assert(data_end < m_data.allocatedSize());
1194
- StorageIndex new_end = convert_index(m_data.allocatedSize());
1195
- for(Index k=outer+1; k<=m_outerSize; ++k)
1196
- if(m_outerIndex[k]==data_end)
1197
- m_outerIndex[k] = new_end;
1198
- }
1199
- return m_data.value(p);
1619
+ eigen_assert((dst == end || m_data.index(dst) != inner) &&
1620
+ "you cannot insert an element that already exists, you must call coeffRef to this end");
1621
+ return insertUncompressedAtByOuterInner(outer, inner, dst);
1622
+ }
1623
+
1624
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1625
+ EIGEN_DEPRECATED EIGEN_DONT_INLINE typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1626
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insertCompressed(Index row, Index col) {
1627
+ eigen_assert(isCompressed());
1628
+ Index outer = IsRowMajor ? row : col;
1629
+ Index inner = IsRowMajor ? col : row;
1630
+ Index start = m_outerIndex[outer];
1631
+ Index end = m_outerIndex[outer + 1];
1632
+ Index dst = start == end ? end : m_data.searchLowerIndex(start, end, inner);
1633
+ eigen_assert((dst == end || m_data.index(dst) != inner) &&
1634
+ "you cannot insert an element that already exists, you must call coeffRef to this end");
1635
+ return insertCompressedAtByOuterInner(outer, inner, dst);
1636
+ }
1637
+
1638
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1639
+ typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1640
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insertCompressedAtByOuterInner(Index outer, Index inner, Index dst) {
1641
+ eigen_assert(isCompressed());
1642
+ // compressed insertion always requires expanding the buffer
1643
+ // first, check if there is adequate allocated memory
1644
+ if (m_data.allocatedSize() <= m_data.size()) {
1645
+ // if there is no capacity for a single insertion, double the capacity
1646
+ // increase capacity by a minimum of 32
1647
+ Index minReserve = 32;
1648
+ Index reserveSize = numext::maxi(minReserve, m_data.allocatedSize());
1649
+ m_data.reserve(reserveSize);
1200
1650
  }
1201
-
1202
- // Second case: the next inner-vector is packed to the end
1203
- // and the current inner-vector end match the used-space.
1204
- if(m_outerIndex[outer+1]==data_end && m_outerIndex[outer]+m_innerNonZeros[outer]==m_data.size())
1205
- {
1206
- eigen_internal_assert(outer+1==m_outerSize || m_innerNonZeros[outer+1]==0);
1207
-
1208
- // add space for the new element
1209
- ++m_innerNonZeros[outer];
1210
- m_data.resize(m_data.size()+1);
1211
-
1212
- // check for reallocation
1213
- if(data_end != m_data.allocatedSize())
1214
- {
1215
- // m_data has been reallocated
1216
- // -> move remaining inner-vectors back to the end of the free-space
1217
- // so that the entire free-space is allocated to the current inner-vector.
1218
- eigen_internal_assert(data_end < m_data.allocatedSize());
1219
- StorageIndex new_end = convert_index(m_data.allocatedSize());
1220
- for(Index k=outer+1; k<=m_outerSize; ++k)
1221
- if(m_outerIndex[k]==data_end)
1222
- m_outerIndex[k] = new_end;
1651
+ m_data.resize(m_data.size() + 1);
1652
+ Index chunkSize = m_outerIndex[m_outerSize] - dst;
1653
+ // shift the existing data to the right if necessary
1654
+ m_data.moveChunk(dst, dst + 1, chunkSize);
1655
+ // update nonzero counts
1656
+ // potentially O(outerSize) bottleneck!
1657
+ for (Index j = outer; j < m_outerSize; j++) m_outerIndex[j + 1]++;
1658
+ // initialize the coefficient
1659
+ m_data.index(dst) = StorageIndex(inner);
1660
+ m_data.value(dst) = Scalar(0);
1661
+ // return a reference to the coefficient
1662
+ return m_data.value(dst);
1663
+ }
1664
+
1665
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1666
+ typename SparseMatrix<Scalar_, Options_, StorageIndex_>::Scalar&
1667
+ SparseMatrix<Scalar_, Options_, StorageIndex_>::insertUncompressedAtByOuterInner(Index outer, Index inner, Index dst) {
1668
+ eigen_assert(!isCompressed());
1669
+ // find a vector with capacity, starting at `outer` and searching to the left and right
1670
+ for (Index leftTarget = outer - 1, rightTarget = outer; (leftTarget >= 0) || (rightTarget < m_outerSize);) {
1671
+ if (rightTarget < m_outerSize) {
1672
+ Index start = m_outerIndex[rightTarget];
1673
+ Index end = start + m_innerNonZeros[rightTarget];
1674
+ Index nextStart = m_outerIndex[rightTarget + 1];
1675
+ Index capacity = nextStart - end;
1676
+ if (capacity > 0) {
1677
+ // move [dst, end) to dst+1 and insert at dst
1678
+ Index chunkSize = end - dst;
1679
+ if (chunkSize > 0) m_data.moveChunk(dst, dst + 1, chunkSize);
1680
+ m_innerNonZeros[outer]++;
1681
+ for (Index j = outer; j < rightTarget; j++) m_outerIndex[j + 1]++;
1682
+ m_data.index(dst) = StorageIndex(inner);
1683
+ m_data.value(dst) = Scalar(0);
1684
+ return m_data.value(dst);
1685
+ }
1686
+ rightTarget++;
1223
1687
  }
1224
-
1225
- // and insert it at the right position (sorted insertion)
1226
- Index startId = m_outerIndex[outer];
1227
- Index p = m_outerIndex[outer]+m_innerNonZeros[outer]-1;
1228
- while ( (p > startId) && (m_data.index(p-1) > inner) )
1229
- {
1230
- m_data.index(p) = m_data.index(p-1);
1231
- m_data.value(p) = m_data.value(p-1);
1232
- --p;
1688
+ if (leftTarget >= 0) {
1689
+ Index start = m_outerIndex[leftTarget];
1690
+ Index end = start + m_innerNonZeros[leftTarget];
1691
+ Index nextStart = m_outerIndex[leftTarget + 1];
1692
+ Index capacity = nextStart - end;
1693
+ if (capacity > 0) {
1694
+ // tricky: dst is a lower bound, so we must insert at dst-1 when shifting left
1695
+ // move [nextStart, dst) to nextStart-1 and insert at dst-1
1696
+ Index chunkSize = dst - nextStart;
1697
+ if (chunkSize > 0) m_data.moveChunk(nextStart, nextStart - 1, chunkSize);
1698
+ m_innerNonZeros[outer]++;
1699
+ for (Index j = leftTarget; j < outer; j++) m_outerIndex[j + 1]--;
1700
+ m_data.index(dst - 1) = StorageIndex(inner);
1701
+ m_data.value(dst - 1) = Scalar(0);
1702
+ return m_data.value(dst - 1);
1703
+ }
1704
+ leftTarget--;
1233
1705
  }
1234
-
1235
- m_data.index(p) = convert_index(inner);
1236
- return (m_data.value(p) = 0);
1237
1706
  }
1238
-
1239
- if(m_data.size() != m_data.allocatedSize())
1240
- {
1241
- // make sure the matrix is compatible to random un-compressed insertion:
1242
- m_data.resize(m_data.allocatedSize());
1243
- this->reserveInnerVectors(Array<StorageIndex,Dynamic,1>::Constant(m_outerSize, 2));
1707
+
1708
+ // no room for interior insertion
1709
+ // nonZeros() == m_data.size()
1710
+ // record offset as outerIndxPtr will change
1711
+ Index dst_offset = dst - m_outerIndex[outer];
1712
+ // allocate space for random insertion
1713
+ if (m_data.allocatedSize() == 0) {
1714
+ // fast method to allocate space for one element per vector in empty matrix
1715
+ m_data.resize(m_outerSize);
1716
+ std::iota(m_outerIndex, m_outerIndex + m_outerSize + 1, StorageIndex(0));
1717
+ } else {
1718
+ // check for integer overflow: if maxReserveSize == 0, insertion is not possible
1719
+ Index maxReserveSize = static_cast<Index>(NumTraits<StorageIndex>::highest()) - m_data.allocatedSize();
1720
+ eigen_assert(maxReserveSize > 0);
1721
+ if (m_outerSize <= maxReserveSize) {
1722
+ // allocate space for one additional element per vector
1723
+ reserveInnerVectors(IndexVector::Constant(m_outerSize, 1));
1724
+ } else {
1725
+ // handle the edge case where StorageIndex is insufficient to reserve outerSize additional elements
1726
+ // allocate space for one additional element in the interval [outer,maxReserveSize)
1727
+ typedef internal::sparse_reserve_op<StorageIndex> ReserveSizesOp;
1728
+ typedef CwiseNullaryOp<ReserveSizesOp, IndexVector> ReserveSizesXpr;
1729
+ ReserveSizesXpr reserveSizesXpr(m_outerSize, 1, ReserveSizesOp(outer, m_outerSize, maxReserveSize));
1730
+ reserveInnerVectors(reserveSizesXpr);
1731
+ }
1244
1732
  }
1245
-
1246
- return insertUncompressed(row,col);
1733
+ // insert element at `dst` with new outer indices
1734
+ Index start = m_outerIndex[outer];
1735
+ Index end = start + m_innerNonZeros[outer];
1736
+ Index new_dst = start + dst_offset;
1737
+ Index chunkSize = end - new_dst;
1738
+ if (chunkSize > 0) m_data.moveChunk(new_dst, new_dst + 1, chunkSize);
1739
+ m_innerNonZeros[outer]++;
1740
+ m_data.index(new_dst) = StorageIndex(inner);
1741
+ m_data.value(new_dst) = Scalar(0);
1742
+ return m_data.value(new_dst);
1247
1743
  }
1248
-
1249
- template<typename _Scalar, int _Options, typename _StorageIndex>
1250
- EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insertUncompressed(Index row, Index col)
1251
- {
1252
- eigen_assert(!isCompressed());
1253
1744
 
1254
- const Index outer = IsRowMajor ? row : col;
1255
- const StorageIndex inner = convert_index(IsRowMajor ? col : row);
1745
+ namespace internal {
1746
+
1747
+ template <typename Scalar_, int Options_, typename StorageIndex_>
1748
+ struct evaluator<SparseMatrix<Scalar_, Options_, StorageIndex_>>
1749
+ : evaluator<SparseCompressedBase<SparseMatrix<Scalar_, Options_, StorageIndex_>>> {
1750
+ typedef evaluator<SparseCompressedBase<SparseMatrix<Scalar_, Options_, StorageIndex_>>> Base;
1751
+ typedef SparseMatrix<Scalar_, Options_, StorageIndex_> SparseMatrixType;
1752
+ evaluator() : Base() {}
1753
+ explicit evaluator(const SparseMatrixType& mat) : Base(mat) {}
1754
+ };
1256
1755
 
1257
- Index room = m_outerIndex[outer+1] - m_outerIndex[outer];
1258
- StorageIndex innerNNZ = m_innerNonZeros[outer];
1259
- if(innerNNZ>=room)
1260
- {
1261
- // this inner vector is full, we need to reallocate the whole buffer :(
1262
- reserve(SingletonVector(outer,std::max<StorageIndex>(2,innerNNZ)));
1263
- }
1756
+ } // namespace internal
1757
+
1758
+ // Specialization for SparseMatrix.
1759
+ // Serializes [rows, cols, isCompressed, outerSize, innerBufferSize,
1760
+ // innerNonZeros, outerIndices, innerIndices, values].
1761
+ template <typename Scalar, int Options, typename StorageIndex>
1762
+ class Serializer<SparseMatrix<Scalar, Options, StorageIndex>, void> {
1763
+ public:
1764
+ typedef SparseMatrix<Scalar, Options, StorageIndex> SparseMat;
1765
+
1766
+ struct Header {
1767
+ typename SparseMat::Index rows;
1768
+ typename SparseMat::Index cols;
1769
+ bool compressed;
1770
+ Index outer_size;
1771
+ Index inner_buffer_size;
1772
+ };
1264
1773
 
1265
- Index startId = m_outerIndex[outer];
1266
- Index p = startId + m_innerNonZeros[outer];
1267
- while ( (p > startId) && (m_data.index(p-1) > inner) )
1268
- {
1269
- m_data.index(p) = m_data.index(p-1);
1270
- m_data.value(p) = m_data.value(p-1);
1271
- --p;
1774
+ EIGEN_DEVICE_FUNC size_t size(const SparseMat& value) const {
1775
+ // innerNonZeros.
1776
+ std::size_t num_storage_indices = value.isCompressed() ? 0 : value.outerSize();
1777
+ // Outer indices.
1778
+ num_storage_indices += value.outerSize() + 1;
1779
+ // Inner indices.
1780
+ const StorageIndex inner_buffer_size = value.outerIndexPtr()[value.outerSize()];
1781
+ num_storage_indices += inner_buffer_size;
1782
+ // Values.
1783
+ std::size_t num_values = inner_buffer_size;
1784
+ return sizeof(Header) + sizeof(Scalar) * num_values + sizeof(StorageIndex) * num_storage_indices;
1272
1785
  }
1273
- eigen_assert((p<=startId || m_data.index(p-1)!=inner) && "you cannot insert an element that already exists, you must call coeffRef to this end");
1274
1786
 
1275
- m_innerNonZeros[outer]++;
1787
+ EIGEN_DEVICE_FUNC uint8_t* serialize(uint8_t* dest, uint8_t* end, const SparseMat& value) {
1788
+ if (EIGEN_PREDICT_FALSE(dest == nullptr)) return nullptr;
1789
+ if (EIGEN_PREDICT_FALSE(dest + size(value) > end)) return nullptr;
1790
+
1791
+ const size_t header_bytes = sizeof(Header);
1792
+ Header header = {value.rows(), value.cols(), value.isCompressed(), value.outerSize(),
1793
+ value.outerIndexPtr()[value.outerSize()]};
1794
+ EIGEN_USING_STD(memcpy)
1795
+ memcpy(dest, &header, header_bytes);
1796
+ dest += header_bytes;
1797
+
1798
+ // innerNonZeros.
1799
+ if (!header.compressed) {
1800
+ std::size_t data_bytes = sizeof(StorageIndex) * header.outer_size;
1801
+ memcpy(dest, value.innerNonZeroPtr(), data_bytes);
1802
+ dest += data_bytes;
1803
+ }
1276
1804
 
1277
- m_data.index(p) = inner;
1278
- return (m_data.value(p) = Scalar(0));
1279
- }
1805
+ // Outer indices.
1806
+ std::size_t data_bytes = sizeof(StorageIndex) * (header.outer_size + 1);
1807
+ memcpy(dest, value.outerIndexPtr(), data_bytes);
1808
+ dest += data_bytes;
1280
1809
 
1281
- template<typename _Scalar, int _Options, typename _StorageIndex>
1282
- EIGEN_DONT_INLINE typename SparseMatrix<_Scalar,_Options,_StorageIndex>::Scalar& SparseMatrix<_Scalar,_Options,_StorageIndex>::insertCompressed(Index row, Index col)
1283
- {
1284
- eigen_assert(isCompressed());
1810
+ // Inner indices.
1811
+ data_bytes = sizeof(StorageIndex) * header.inner_buffer_size;
1812
+ memcpy(dest, value.innerIndexPtr(), data_bytes);
1813
+ dest += data_bytes;
1285
1814
 
1286
- const Index outer = IsRowMajor ? row : col;
1287
- const Index inner = IsRowMajor ? col : row;
1815
+ // Values.
1816
+ data_bytes = sizeof(Scalar) * header.inner_buffer_size;
1817
+ memcpy(dest, value.valuePtr(), data_bytes);
1818
+ dest += data_bytes;
1288
1819
 
1289
- Index previousOuter = outer;
1290
- if (m_outerIndex[outer+1]==0)
1291
- {
1292
- // we start a new inner vector
1293
- while (previousOuter>=0 && m_outerIndex[previousOuter]==0)
1294
- {
1295
- m_outerIndex[previousOuter] = convert_index(m_data.size());
1296
- --previousOuter;
1297
- }
1298
- m_outerIndex[outer+1] = m_outerIndex[outer];
1820
+ return dest;
1299
1821
  }
1300
1822
 
1301
- // here we have to handle the tricky case where the outerIndex array
1302
- // starts with: [ 0 0 0 0 0 1 ...] and we are inserted in, e.g.,
1303
- // the 2nd inner vector...
1304
- bool isLastVec = (!(previousOuter==-1 && m_data.size()!=0))
1305
- && (std::size_t(m_outerIndex[outer+1]) == m_data.size());
1306
-
1307
- std::size_t startId = m_outerIndex[outer];
1308
- // FIXME let's make sure sizeof(long int) == sizeof(std::size_t)
1309
- std::size_t p = m_outerIndex[outer+1];
1310
- ++m_outerIndex[outer+1];
1311
-
1312
- double reallocRatio = 1;
1313
- if (m_data.allocatedSize()<=m_data.size())
1314
- {
1315
- // if there is no preallocated memory, let's reserve a minimum of 32 elements
1316
- if (m_data.size()==0)
1317
- {
1318
- m_data.reserve(32);
1319
- }
1320
- else
1321
- {
1322
- // we need to reallocate the data, to reduce multiple reallocations
1323
- // we use a smart resize algorithm based on the current filling ratio
1324
- // in addition, we use double to avoid integers overflows
1325
- double nnzEstimate = double(m_outerIndex[outer])*double(m_outerSize)/double(outer+1);
1326
- reallocRatio = (nnzEstimate-double(m_data.size()))/double(m_data.size());
1327
- // furthermore we bound the realloc ratio to:
1328
- // 1) reduce multiple minor realloc when the matrix is almost filled
1329
- // 2) avoid to allocate too much memory when the matrix is almost empty
1330
- reallocRatio = (std::min)((std::max)(reallocRatio,1.5),8.);
1823
+ EIGEN_DEVICE_FUNC const uint8_t* deserialize(const uint8_t* src, const uint8_t* end, SparseMat& value) const {
1824
+ if (EIGEN_PREDICT_FALSE(src == nullptr)) return nullptr;
1825
+ if (EIGEN_PREDICT_FALSE(src + sizeof(Header) > end)) return nullptr;
1826
+
1827
+ const size_t header_bytes = sizeof(Header);
1828
+ Header header;
1829
+ EIGEN_USING_STD(memcpy)
1830
+ memcpy(&header, src, header_bytes);
1831
+ src += header_bytes;
1832
+
1833
+ value.setZero();
1834
+ value.resize(header.rows, header.cols);
1835
+ if (header.compressed) {
1836
+ value.makeCompressed();
1837
+ } else {
1838
+ value.uncompress();
1331
1839
  }
1332
- }
1333
- m_data.resize(m_data.size()+1,reallocRatio);
1334
1840
 
1335
- if (!isLastVec)
1336
- {
1337
- if (previousOuter==-1)
1338
- {
1339
- // oops wrong guess.
1340
- // let's correct the outer offsets
1341
- for (Index k=0; k<=(outer+1); ++k)
1342
- m_outerIndex[k] = 0;
1343
- Index k=outer+1;
1344
- while(m_outerIndex[k]==0)
1345
- m_outerIndex[k++] = 1;
1346
- while (k<=m_outerSize && m_outerIndex[k]!=0)
1347
- m_outerIndex[k++]++;
1348
- p = 0;
1349
- --k;
1350
- k = m_outerIndex[k]-1;
1351
- while (k>0)
1352
- {
1353
- m_data.index(k) = m_data.index(k-1);
1354
- m_data.value(k) = m_data.value(k-1);
1355
- k--;
1356
- }
1357
- }
1358
- else
1359
- {
1360
- // we are not inserting into the last inner vec
1361
- // update outer indices:
1362
- Index j = outer+2;
1363
- while (j<=m_outerSize && m_outerIndex[j]!=0)
1364
- m_outerIndex[j++]++;
1365
- --j;
1366
- // shift data of last vecs:
1367
- Index k = m_outerIndex[j]-1;
1368
- while (k>=Index(p))
1369
- {
1370
- m_data.index(k) = m_data.index(k-1);
1371
- m_data.value(k) = m_data.value(k-1);
1372
- k--;
1373
- }
1841
+ // Adjust value ptr size.
1842
+ value.data().resize(header.inner_buffer_size);
1843
+
1844
+ // Initialize compressed state and inner non-zeros.
1845
+ if (!header.compressed) {
1846
+ // Inner non-zero counts.
1847
+ std::size_t data_bytes = sizeof(StorageIndex) * header.outer_size;
1848
+ if (EIGEN_PREDICT_FALSE(src + data_bytes > end)) return nullptr;
1849
+ memcpy(value.innerNonZeroPtr(), src, data_bytes);
1850
+ src += data_bytes;
1374
1851
  }
1375
- }
1376
1852
 
1377
- while ( (p > startId) && (m_data.index(p-1) > inner) )
1378
- {
1379
- m_data.index(p) = m_data.index(p-1);
1380
- m_data.value(p) = m_data.value(p-1);
1381
- --p;
1853
+ // Outer indices.
1854
+ std::size_t data_bytes = sizeof(StorageIndex) * (header.outer_size + 1);
1855
+ if (EIGEN_PREDICT_FALSE(src + data_bytes > end)) return nullptr;
1856
+ memcpy(value.outerIndexPtr(), src, data_bytes);
1857
+ src += data_bytes;
1858
+
1859
+ // Inner indices.
1860
+ data_bytes = sizeof(StorageIndex) * header.inner_buffer_size;
1861
+ if (EIGEN_PREDICT_FALSE(src + data_bytes > end)) return nullptr;
1862
+ memcpy(value.innerIndexPtr(), src, data_bytes);
1863
+ src += data_bytes;
1864
+
1865
+ // Values.
1866
+ data_bytes = sizeof(Scalar) * header.inner_buffer_size;
1867
+ if (EIGEN_PREDICT_FALSE(src + data_bytes > end)) return nullptr;
1868
+ memcpy(value.valuePtr(), src, data_bytes);
1869
+ src += data_bytes;
1870
+ return src;
1382
1871
  }
1383
-
1384
- m_data.index(p) = inner;
1385
- return (m_data.value(p) = Scalar(0));
1386
- }
1387
-
1388
- namespace internal {
1389
-
1390
- template<typename _Scalar, int _Options, typename _StorageIndex>
1391
- struct evaluator<SparseMatrix<_Scalar,_Options,_StorageIndex> >
1392
- : evaluator<SparseCompressedBase<SparseMatrix<_Scalar,_Options,_StorageIndex> > >
1393
- {
1394
- typedef evaluator<SparseCompressedBase<SparseMatrix<_Scalar,_Options,_StorageIndex> > > Base;
1395
- typedef SparseMatrix<_Scalar,_Options,_StorageIndex> SparseMatrixType;
1396
- evaluator() : Base() {}
1397
- explicit evaluator(const SparseMatrixType &mat) : Base(mat) {}
1398
1872
  };
1399
1873
 
1400
- }
1401
-
1402
- } // end namespace Eigen
1874
+ } // end namespace Eigen
1403
1875
 
1404
- #endif // EIGEN_SPARSEMATRIX_H
1876
+ #endif // EIGEN_SPARSEMATRIX_H