tomoto 0.1.0

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 (420) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +123 -0
  5. data/ext/tomoto/ext.cpp +245 -0
  6. data/ext/tomoto/extconf.rb +28 -0
  7. data/lib/tomoto.rb +12 -0
  8. data/lib/tomoto/ct.rb +11 -0
  9. data/lib/tomoto/hdp.rb +11 -0
  10. data/lib/tomoto/lda.rb +67 -0
  11. data/lib/tomoto/version.rb +3 -0
  12. data/vendor/EigenRand/EigenRand/Core.h +1139 -0
  13. data/vendor/EigenRand/EigenRand/Dists/Basic.h +111 -0
  14. data/vendor/EigenRand/EigenRand/Dists/Discrete.h +877 -0
  15. data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +108 -0
  16. data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +626 -0
  17. data/vendor/EigenRand/EigenRand/EigenRand +19 -0
  18. data/vendor/EigenRand/EigenRand/Macro.h +24 -0
  19. data/vendor/EigenRand/EigenRand/MorePacketMath.h +978 -0
  20. data/vendor/EigenRand/EigenRand/PacketFilter.h +286 -0
  21. data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +624 -0
  22. data/vendor/EigenRand/EigenRand/RandUtils.h +413 -0
  23. data/vendor/EigenRand/EigenRand/doc.h +220 -0
  24. data/vendor/EigenRand/LICENSE +21 -0
  25. data/vendor/EigenRand/README.md +288 -0
  26. data/vendor/eigen/COPYING.BSD +26 -0
  27. data/vendor/eigen/COPYING.GPL +674 -0
  28. data/vendor/eigen/COPYING.LGPL +502 -0
  29. data/vendor/eigen/COPYING.MINPACK +52 -0
  30. data/vendor/eigen/COPYING.MPL2 +373 -0
  31. data/vendor/eigen/COPYING.README +18 -0
  32. data/vendor/eigen/Eigen/CMakeLists.txt +19 -0
  33. data/vendor/eigen/Eigen/Cholesky +46 -0
  34. data/vendor/eigen/Eigen/CholmodSupport +48 -0
  35. data/vendor/eigen/Eigen/Core +537 -0
  36. data/vendor/eigen/Eigen/Dense +7 -0
  37. data/vendor/eigen/Eigen/Eigen +2 -0
  38. data/vendor/eigen/Eigen/Eigenvalues +61 -0
  39. data/vendor/eigen/Eigen/Geometry +62 -0
  40. data/vendor/eigen/Eigen/Householder +30 -0
  41. data/vendor/eigen/Eigen/IterativeLinearSolvers +48 -0
  42. data/vendor/eigen/Eigen/Jacobi +33 -0
  43. data/vendor/eigen/Eigen/LU +50 -0
  44. data/vendor/eigen/Eigen/MetisSupport +35 -0
  45. data/vendor/eigen/Eigen/OrderingMethods +73 -0
  46. data/vendor/eigen/Eigen/PaStiXSupport +48 -0
  47. data/vendor/eigen/Eigen/PardisoSupport +35 -0
  48. data/vendor/eigen/Eigen/QR +51 -0
  49. data/vendor/eigen/Eigen/QtAlignedMalloc +40 -0
  50. data/vendor/eigen/Eigen/SPQRSupport +34 -0
  51. data/vendor/eigen/Eigen/SVD +51 -0
  52. data/vendor/eigen/Eigen/Sparse +36 -0
  53. data/vendor/eigen/Eigen/SparseCholesky +45 -0
  54. data/vendor/eigen/Eigen/SparseCore +69 -0
  55. data/vendor/eigen/Eigen/SparseLU +46 -0
  56. data/vendor/eigen/Eigen/SparseQR +37 -0
  57. data/vendor/eigen/Eigen/StdDeque +27 -0
  58. data/vendor/eigen/Eigen/StdList +26 -0
  59. data/vendor/eigen/Eigen/StdVector +27 -0
  60. data/vendor/eigen/Eigen/SuperLUSupport +64 -0
  61. data/vendor/eigen/Eigen/UmfPackSupport +40 -0
  62. data/vendor/eigen/Eigen/src/Cholesky/LDLT.h +673 -0
  63. data/vendor/eigen/Eigen/src/Cholesky/LLT.h +542 -0
  64. data/vendor/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h +99 -0
  65. data/vendor/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +639 -0
  66. data/vendor/eigen/Eigen/src/Core/Array.h +329 -0
  67. data/vendor/eigen/Eigen/src/Core/ArrayBase.h +226 -0
  68. data/vendor/eigen/Eigen/src/Core/ArrayWrapper.h +209 -0
  69. data/vendor/eigen/Eigen/src/Core/Assign.h +90 -0
  70. data/vendor/eigen/Eigen/src/Core/AssignEvaluator.h +935 -0
  71. data/vendor/eigen/Eigen/src/Core/Assign_MKL.h +178 -0
  72. data/vendor/eigen/Eigen/src/Core/BandMatrix.h +353 -0
  73. data/vendor/eigen/Eigen/src/Core/Block.h +452 -0
  74. data/vendor/eigen/Eigen/src/Core/BooleanRedux.h +164 -0
  75. data/vendor/eigen/Eigen/src/Core/CommaInitializer.h +160 -0
  76. data/vendor/eigen/Eigen/src/Core/ConditionEstimator.h +175 -0
  77. data/vendor/eigen/Eigen/src/Core/CoreEvaluators.h +1688 -0
  78. data/vendor/eigen/Eigen/src/Core/CoreIterators.h +127 -0
  79. data/vendor/eigen/Eigen/src/Core/CwiseBinaryOp.h +184 -0
  80. data/vendor/eigen/Eigen/src/Core/CwiseNullaryOp.h +866 -0
  81. data/vendor/eigen/Eigen/src/Core/CwiseTernaryOp.h +197 -0
  82. data/vendor/eigen/Eigen/src/Core/CwiseUnaryOp.h +103 -0
  83. data/vendor/eigen/Eigen/src/Core/CwiseUnaryView.h +128 -0
  84. data/vendor/eigen/Eigen/src/Core/DenseBase.h +611 -0
  85. data/vendor/eigen/Eigen/src/Core/DenseCoeffsBase.h +681 -0
  86. data/vendor/eigen/Eigen/src/Core/DenseStorage.h +570 -0
  87. data/vendor/eigen/Eigen/src/Core/Diagonal.h +260 -0
  88. data/vendor/eigen/Eigen/src/Core/DiagonalMatrix.h +343 -0
  89. data/vendor/eigen/Eigen/src/Core/DiagonalProduct.h +28 -0
  90. data/vendor/eigen/Eigen/src/Core/Dot.h +318 -0
  91. data/vendor/eigen/Eigen/src/Core/EigenBase.h +159 -0
  92. data/vendor/eigen/Eigen/src/Core/ForceAlignedAccess.h +146 -0
  93. data/vendor/eigen/Eigen/src/Core/Fuzzy.h +155 -0
  94. data/vendor/eigen/Eigen/src/Core/GeneralProduct.h +455 -0
  95. data/vendor/eigen/Eigen/src/Core/GenericPacketMath.h +593 -0
  96. data/vendor/eigen/Eigen/src/Core/GlobalFunctions.h +187 -0
  97. data/vendor/eigen/Eigen/src/Core/IO.h +225 -0
  98. data/vendor/eigen/Eigen/src/Core/Inverse.h +118 -0
  99. data/vendor/eigen/Eigen/src/Core/Map.h +171 -0
  100. data/vendor/eigen/Eigen/src/Core/MapBase.h +303 -0
  101. data/vendor/eigen/Eigen/src/Core/MathFunctions.h +1415 -0
  102. data/vendor/eigen/Eigen/src/Core/MathFunctionsImpl.h +101 -0
  103. data/vendor/eigen/Eigen/src/Core/Matrix.h +459 -0
  104. data/vendor/eigen/Eigen/src/Core/MatrixBase.h +529 -0
  105. data/vendor/eigen/Eigen/src/Core/NestByValue.h +110 -0
  106. data/vendor/eigen/Eigen/src/Core/NoAlias.h +108 -0
  107. data/vendor/eigen/Eigen/src/Core/NumTraits.h +248 -0
  108. data/vendor/eigen/Eigen/src/Core/PermutationMatrix.h +633 -0
  109. data/vendor/eigen/Eigen/src/Core/PlainObjectBase.h +1035 -0
  110. data/vendor/eigen/Eigen/src/Core/Product.h +186 -0
  111. data/vendor/eigen/Eigen/src/Core/ProductEvaluators.h +1112 -0
  112. data/vendor/eigen/Eigen/src/Core/Random.h +182 -0
  113. data/vendor/eigen/Eigen/src/Core/Redux.h +505 -0
  114. data/vendor/eigen/Eigen/src/Core/Ref.h +283 -0
  115. data/vendor/eigen/Eigen/src/Core/Replicate.h +142 -0
  116. data/vendor/eigen/Eigen/src/Core/ReturnByValue.h +117 -0
  117. data/vendor/eigen/Eigen/src/Core/Reverse.h +211 -0
  118. data/vendor/eigen/Eigen/src/Core/Select.h +162 -0
  119. data/vendor/eigen/Eigen/src/Core/SelfAdjointView.h +352 -0
  120. data/vendor/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +47 -0
  121. data/vendor/eigen/Eigen/src/Core/Solve.h +188 -0
  122. data/vendor/eigen/Eigen/src/Core/SolveTriangular.h +235 -0
  123. data/vendor/eigen/Eigen/src/Core/SolverBase.h +130 -0
  124. data/vendor/eigen/Eigen/src/Core/StableNorm.h +221 -0
  125. data/vendor/eigen/Eigen/src/Core/Stride.h +111 -0
  126. data/vendor/eigen/Eigen/src/Core/Swap.h +67 -0
  127. data/vendor/eigen/Eigen/src/Core/Transpose.h +403 -0
  128. data/vendor/eigen/Eigen/src/Core/Transpositions.h +407 -0
  129. data/vendor/eigen/Eigen/src/Core/TriangularMatrix.h +983 -0
  130. data/vendor/eigen/Eigen/src/Core/VectorBlock.h +96 -0
  131. data/vendor/eigen/Eigen/src/Core/VectorwiseOp.h +695 -0
  132. data/vendor/eigen/Eigen/src/Core/Visitor.h +273 -0
  133. data/vendor/eigen/Eigen/src/Core/arch/AVX/Complex.h +451 -0
  134. data/vendor/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +439 -0
  135. data/vendor/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +637 -0
  136. data/vendor/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +51 -0
  137. data/vendor/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +391 -0
  138. data/vendor/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +1316 -0
  139. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +430 -0
  140. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +322 -0
  141. data/vendor/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +1061 -0
  142. data/vendor/eigen/Eigen/src/Core/arch/CUDA/Complex.h +103 -0
  143. data/vendor/eigen/Eigen/src/Core/arch/CUDA/Half.h +674 -0
  144. data/vendor/eigen/Eigen/src/Core/arch/CUDA/MathFunctions.h +91 -0
  145. data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMath.h +333 -0
  146. data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMathHalf.h +1124 -0
  147. data/vendor/eigen/Eigen/src/Core/arch/CUDA/TypeCasting.h +212 -0
  148. data/vendor/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +29 -0
  149. data/vendor/eigen/Eigen/src/Core/arch/Default/Settings.h +49 -0
  150. data/vendor/eigen/Eigen/src/Core/arch/NEON/Complex.h +490 -0
  151. data/vendor/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +91 -0
  152. data/vendor/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +760 -0
  153. data/vendor/eigen/Eigen/src/Core/arch/SSE/Complex.h +471 -0
  154. data/vendor/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +562 -0
  155. data/vendor/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +895 -0
  156. data/vendor/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +77 -0
  157. data/vendor/eigen/Eigen/src/Core/arch/ZVector/Complex.h +397 -0
  158. data/vendor/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +137 -0
  159. data/vendor/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +945 -0
  160. data/vendor/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +168 -0
  161. data/vendor/eigen/Eigen/src/Core/functors/BinaryFunctors.h +475 -0
  162. data/vendor/eigen/Eigen/src/Core/functors/NullaryFunctors.h +188 -0
  163. data/vendor/eigen/Eigen/src/Core/functors/StlFunctors.h +136 -0
  164. data/vendor/eigen/Eigen/src/Core/functors/TernaryFunctors.h +25 -0
  165. data/vendor/eigen/Eigen/src/Core/functors/UnaryFunctors.h +792 -0
  166. data/vendor/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +2156 -0
  167. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +492 -0
  168. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +311 -0
  169. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +145 -0
  170. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +122 -0
  171. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +619 -0
  172. data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +136 -0
  173. data/vendor/eigen/Eigen/src/Core/products/Parallelizer.h +163 -0
  174. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +521 -0
  175. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +287 -0
  176. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +260 -0
  177. data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +118 -0
  178. data/vendor/eigen/Eigen/src/Core/products/SelfadjointProduct.h +133 -0
  179. data/vendor/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +93 -0
  180. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +466 -0
  181. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +315 -0
  182. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +350 -0
  183. data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +255 -0
  184. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +335 -0
  185. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +163 -0
  186. data/vendor/eigen/Eigen/src/Core/products/TriangularSolverVector.h +145 -0
  187. data/vendor/eigen/Eigen/src/Core/util/BlasUtil.h +398 -0
  188. data/vendor/eigen/Eigen/src/Core/util/Constants.h +547 -0
  189. data/vendor/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +83 -0
  190. data/vendor/eigen/Eigen/src/Core/util/ForwardDeclarations.h +302 -0
  191. data/vendor/eigen/Eigen/src/Core/util/MKL_support.h +130 -0
  192. data/vendor/eigen/Eigen/src/Core/util/Macros.h +1001 -0
  193. data/vendor/eigen/Eigen/src/Core/util/Memory.h +993 -0
  194. data/vendor/eigen/Eigen/src/Core/util/Meta.h +534 -0
  195. data/vendor/eigen/Eigen/src/Core/util/NonMPL2.h +3 -0
  196. data/vendor/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +27 -0
  197. data/vendor/eigen/Eigen/src/Core/util/StaticAssert.h +218 -0
  198. data/vendor/eigen/Eigen/src/Core/util/XprHelper.h +821 -0
  199. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h +346 -0
  200. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur.h +459 -0
  201. data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +91 -0
  202. data/vendor/eigen/Eigen/src/Eigenvalues/EigenSolver.h +622 -0
  203. data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +418 -0
  204. data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +226 -0
  205. data/vendor/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h +374 -0
  206. data/vendor/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +158 -0
  207. data/vendor/eigen/Eigen/src/Eigenvalues/RealQZ.h +654 -0
  208. data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur.h +546 -0
  209. data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +77 -0
  210. data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +870 -0
  211. data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +87 -0
  212. data/vendor/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h +556 -0
  213. data/vendor/eigen/Eigen/src/Geometry/AlignedBox.h +392 -0
  214. data/vendor/eigen/Eigen/src/Geometry/AngleAxis.h +247 -0
  215. data/vendor/eigen/Eigen/src/Geometry/EulerAngles.h +114 -0
  216. data/vendor/eigen/Eigen/src/Geometry/Homogeneous.h +497 -0
  217. data/vendor/eigen/Eigen/src/Geometry/Hyperplane.h +282 -0
  218. data/vendor/eigen/Eigen/src/Geometry/OrthoMethods.h +234 -0
  219. data/vendor/eigen/Eigen/src/Geometry/ParametrizedLine.h +195 -0
  220. data/vendor/eigen/Eigen/src/Geometry/Quaternion.h +814 -0
  221. data/vendor/eigen/Eigen/src/Geometry/Rotation2D.h +199 -0
  222. data/vendor/eigen/Eigen/src/Geometry/RotationBase.h +206 -0
  223. data/vendor/eigen/Eigen/src/Geometry/Scaling.h +170 -0
  224. data/vendor/eigen/Eigen/src/Geometry/Transform.h +1542 -0
  225. data/vendor/eigen/Eigen/src/Geometry/Translation.h +208 -0
  226. data/vendor/eigen/Eigen/src/Geometry/Umeyama.h +166 -0
  227. data/vendor/eigen/Eigen/src/Geometry/arch/Geometry_SSE.h +161 -0
  228. data/vendor/eigen/Eigen/src/Householder/BlockHouseholder.h +103 -0
  229. data/vendor/eigen/Eigen/src/Householder/Householder.h +172 -0
  230. data/vendor/eigen/Eigen/src/Householder/HouseholderSequence.h +470 -0
  231. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +226 -0
  232. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +228 -0
  233. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +246 -0
  234. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +400 -0
  235. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +462 -0
  236. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +394 -0
  237. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +216 -0
  238. data/vendor/eigen/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +115 -0
  239. data/vendor/eigen/Eigen/src/Jacobi/Jacobi.h +462 -0
  240. data/vendor/eigen/Eigen/src/LU/Determinant.h +101 -0
  241. data/vendor/eigen/Eigen/src/LU/FullPivLU.h +891 -0
  242. data/vendor/eigen/Eigen/src/LU/InverseImpl.h +415 -0
  243. data/vendor/eigen/Eigen/src/LU/PartialPivLU.h +611 -0
  244. data/vendor/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h +83 -0
  245. data/vendor/eigen/Eigen/src/LU/arch/Inverse_SSE.h +338 -0
  246. data/vendor/eigen/Eigen/src/MetisSupport/MetisSupport.h +137 -0
  247. data/vendor/eigen/Eigen/src/OrderingMethods/Amd.h +445 -0
  248. data/vendor/eigen/Eigen/src/OrderingMethods/Eigen_Colamd.h +1843 -0
  249. data/vendor/eigen/Eigen/src/OrderingMethods/Ordering.h +157 -0
  250. data/vendor/eigen/Eigen/src/PaStiXSupport/PaStiXSupport.h +678 -0
  251. data/vendor/eigen/Eigen/src/PardisoSupport/PardisoSupport.h +543 -0
  252. data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR.h +653 -0
  253. data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +97 -0
  254. data/vendor/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h +562 -0
  255. data/vendor/eigen/Eigen/src/QR/FullPivHouseholderQR.h +676 -0
  256. data/vendor/eigen/Eigen/src/QR/HouseholderQR.h +409 -0
  257. data/vendor/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h +68 -0
  258. data/vendor/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +313 -0
  259. data/vendor/eigen/Eigen/src/SVD/BDCSVD.h +1246 -0
  260. data/vendor/eigen/Eigen/src/SVD/JacobiSVD.h +804 -0
  261. data/vendor/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h +91 -0
  262. data/vendor/eigen/Eigen/src/SVD/SVDBase.h +315 -0
  263. data/vendor/eigen/Eigen/src/SVD/UpperBidiagonalization.h +414 -0
  264. data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky.h +689 -0
  265. data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +199 -0
  266. data/vendor/eigen/Eigen/src/SparseCore/AmbiVector.h +377 -0
  267. data/vendor/eigen/Eigen/src/SparseCore/CompressedStorage.h +258 -0
  268. data/vendor/eigen/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +352 -0
  269. data/vendor/eigen/Eigen/src/SparseCore/MappedSparseMatrix.h +67 -0
  270. data/vendor/eigen/Eigen/src/SparseCore/SparseAssign.h +216 -0
  271. data/vendor/eigen/Eigen/src/SparseCore/SparseBlock.h +603 -0
  272. data/vendor/eigen/Eigen/src/SparseCore/SparseColEtree.h +206 -0
  273. data/vendor/eigen/Eigen/src/SparseCore/SparseCompressedBase.h +341 -0
  274. data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +726 -0
  275. data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +148 -0
  276. data/vendor/eigen/Eigen/src/SparseCore/SparseDenseProduct.h +320 -0
  277. data/vendor/eigen/Eigen/src/SparseCore/SparseDiagonalProduct.h +138 -0
  278. data/vendor/eigen/Eigen/src/SparseCore/SparseDot.h +98 -0
  279. data/vendor/eigen/Eigen/src/SparseCore/SparseFuzzy.h +29 -0
  280. data/vendor/eigen/Eigen/src/SparseCore/SparseMap.h +305 -0
  281. data/vendor/eigen/Eigen/src/SparseCore/SparseMatrix.h +1403 -0
  282. data/vendor/eigen/Eigen/src/SparseCore/SparseMatrixBase.h +405 -0
  283. data/vendor/eigen/Eigen/src/SparseCore/SparsePermutation.h +178 -0
  284. data/vendor/eigen/Eigen/src/SparseCore/SparseProduct.h +169 -0
  285. data/vendor/eigen/Eigen/src/SparseCore/SparseRedux.h +49 -0
  286. data/vendor/eigen/Eigen/src/SparseCore/SparseRef.h +397 -0
  287. data/vendor/eigen/Eigen/src/SparseCore/SparseSelfAdjointView.h +656 -0
  288. data/vendor/eigen/Eigen/src/SparseCore/SparseSolverBase.h +124 -0
  289. data/vendor/eigen/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +198 -0
  290. data/vendor/eigen/Eigen/src/SparseCore/SparseTranspose.h +92 -0
  291. data/vendor/eigen/Eigen/src/SparseCore/SparseTriangularView.h +189 -0
  292. data/vendor/eigen/Eigen/src/SparseCore/SparseUtil.h +178 -0
  293. data/vendor/eigen/Eigen/src/SparseCore/SparseVector.h +478 -0
  294. data/vendor/eigen/Eigen/src/SparseCore/SparseView.h +253 -0
  295. data/vendor/eigen/Eigen/src/SparseCore/TriangularSolver.h +315 -0
  296. data/vendor/eigen/Eigen/src/SparseLU/SparseLU.h +773 -0
  297. data/vendor/eigen/Eigen/src/SparseLU/SparseLUImpl.h +66 -0
  298. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Memory.h +226 -0
  299. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Structs.h +110 -0
  300. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +301 -0
  301. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Utils.h +80 -0
  302. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_bmod.h +181 -0
  303. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_dfs.h +179 -0
  304. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +107 -0
  305. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +280 -0
  306. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +126 -0
  307. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +130 -0
  308. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_bmod.h +223 -0
  309. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_dfs.h +258 -0
  310. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pivotL.h +137 -0
  311. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h +136 -0
  312. data/vendor/eigen/Eigen/src/SparseLU/SparseLU_relax_snode.h +83 -0
  313. data/vendor/eigen/Eigen/src/SparseQR/SparseQR.h +745 -0
  314. data/vendor/eigen/Eigen/src/StlSupport/StdDeque.h +126 -0
  315. data/vendor/eigen/Eigen/src/StlSupport/StdList.h +106 -0
  316. data/vendor/eigen/Eigen/src/StlSupport/StdVector.h +131 -0
  317. data/vendor/eigen/Eigen/src/StlSupport/details.h +84 -0
  318. data/vendor/eigen/Eigen/src/SuperLUSupport/SuperLUSupport.h +1027 -0
  319. data/vendor/eigen/Eigen/src/UmfPackSupport/UmfPackSupport.h +506 -0
  320. data/vendor/eigen/Eigen/src/misc/Image.h +82 -0
  321. data/vendor/eigen/Eigen/src/misc/Kernel.h +79 -0
  322. data/vendor/eigen/Eigen/src/misc/RealSvd2x2.h +55 -0
  323. data/vendor/eigen/Eigen/src/misc/blas.h +440 -0
  324. data/vendor/eigen/Eigen/src/misc/lapack.h +152 -0
  325. data/vendor/eigen/Eigen/src/misc/lapacke.h +16291 -0
  326. data/vendor/eigen/Eigen/src/misc/lapacke_mangling.h +17 -0
  327. data/vendor/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +332 -0
  328. data/vendor/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +552 -0
  329. data/vendor/eigen/Eigen/src/plugins/BlockMethods.h +1058 -0
  330. data/vendor/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +115 -0
  331. data/vendor/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +163 -0
  332. data/vendor/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +152 -0
  333. data/vendor/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +85 -0
  334. data/vendor/eigen/README.md +3 -0
  335. data/vendor/eigen/bench/README.txt +55 -0
  336. data/vendor/eigen/bench/btl/COPYING +340 -0
  337. data/vendor/eigen/bench/btl/README +154 -0
  338. data/vendor/eigen/bench/tensors/README +21 -0
  339. data/vendor/eigen/blas/README.txt +6 -0
  340. data/vendor/eigen/demos/mandelbrot/README +10 -0
  341. data/vendor/eigen/demos/mix_eigen_and_c/README +9 -0
  342. data/vendor/eigen/demos/opengl/README +13 -0
  343. data/vendor/eigen/unsupported/Eigen/CXX11/src/Tensor/README.md +1760 -0
  344. data/vendor/eigen/unsupported/README.txt +50 -0
  345. data/vendor/tomotopy/LICENSE +21 -0
  346. data/vendor/tomotopy/README.kr.rst +375 -0
  347. data/vendor/tomotopy/README.rst +382 -0
  348. data/vendor/tomotopy/src/Labeling/FoRelevance.cpp +362 -0
  349. data/vendor/tomotopy/src/Labeling/FoRelevance.h +88 -0
  350. data/vendor/tomotopy/src/Labeling/Labeler.h +50 -0
  351. data/vendor/tomotopy/src/TopicModel/CT.h +37 -0
  352. data/vendor/tomotopy/src/TopicModel/CTModel.cpp +13 -0
  353. data/vendor/tomotopy/src/TopicModel/CTModel.hpp +293 -0
  354. data/vendor/tomotopy/src/TopicModel/DMR.h +51 -0
  355. data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +13 -0
  356. data/vendor/tomotopy/src/TopicModel/DMRModel.hpp +374 -0
  357. data/vendor/tomotopy/src/TopicModel/DT.h +65 -0
  358. data/vendor/tomotopy/src/TopicModel/DTM.h +22 -0
  359. data/vendor/tomotopy/src/TopicModel/DTModel.cpp +15 -0
  360. data/vendor/tomotopy/src/TopicModel/DTModel.hpp +572 -0
  361. data/vendor/tomotopy/src/TopicModel/GDMR.h +37 -0
  362. data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +14 -0
  363. data/vendor/tomotopy/src/TopicModel/GDMRModel.hpp +485 -0
  364. data/vendor/tomotopy/src/TopicModel/HDP.h +74 -0
  365. data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +13 -0
  366. data/vendor/tomotopy/src/TopicModel/HDPModel.hpp +592 -0
  367. data/vendor/tomotopy/src/TopicModel/HLDA.h +40 -0
  368. data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +13 -0
  369. data/vendor/tomotopy/src/TopicModel/HLDAModel.hpp +681 -0
  370. data/vendor/tomotopy/src/TopicModel/HPA.h +27 -0
  371. data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +21 -0
  372. data/vendor/tomotopy/src/TopicModel/HPAModel.hpp +588 -0
  373. data/vendor/tomotopy/src/TopicModel/LDA.h +144 -0
  374. data/vendor/tomotopy/src/TopicModel/LDACVB0Model.hpp +442 -0
  375. data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +13 -0
  376. data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +1058 -0
  377. data/vendor/tomotopy/src/TopicModel/LLDA.h +45 -0
  378. data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +13 -0
  379. data/vendor/tomotopy/src/TopicModel/LLDAModel.hpp +203 -0
  380. data/vendor/tomotopy/src/TopicModel/MGLDA.h +63 -0
  381. data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +17 -0
  382. data/vendor/tomotopy/src/TopicModel/MGLDAModel.hpp +558 -0
  383. data/vendor/tomotopy/src/TopicModel/PA.h +43 -0
  384. data/vendor/tomotopy/src/TopicModel/PAModel.cpp +13 -0
  385. data/vendor/tomotopy/src/TopicModel/PAModel.hpp +467 -0
  386. data/vendor/tomotopy/src/TopicModel/PLDA.h +17 -0
  387. data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +13 -0
  388. data/vendor/tomotopy/src/TopicModel/PLDAModel.hpp +214 -0
  389. data/vendor/tomotopy/src/TopicModel/SLDA.h +54 -0
  390. data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +17 -0
  391. data/vendor/tomotopy/src/TopicModel/SLDAModel.hpp +456 -0
  392. data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +692 -0
  393. data/vendor/tomotopy/src/Utils/AliasMethod.hpp +169 -0
  394. data/vendor/tomotopy/src/Utils/Dictionary.h +80 -0
  395. data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +181 -0
  396. data/vendor/tomotopy/src/Utils/LBFGS.h +202 -0
  397. data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBacktracking.h +120 -0
  398. data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBracketing.h +122 -0
  399. data/vendor/tomotopy/src/Utils/LBFGS/Param.h +213 -0
  400. data/vendor/tomotopy/src/Utils/LUT.hpp +82 -0
  401. data/vendor/tomotopy/src/Utils/MultiNormalDistribution.hpp +69 -0
  402. data/vendor/tomotopy/src/Utils/PolyaGamma.hpp +200 -0
  403. data/vendor/tomotopy/src/Utils/PolyaGammaHybrid.hpp +672 -0
  404. data/vendor/tomotopy/src/Utils/ThreadPool.hpp +150 -0
  405. data/vendor/tomotopy/src/Utils/Trie.hpp +220 -0
  406. data/vendor/tomotopy/src/Utils/TruncMultiNormal.hpp +94 -0
  407. data/vendor/tomotopy/src/Utils/Utils.hpp +337 -0
  408. data/vendor/tomotopy/src/Utils/avx_gamma.h +46 -0
  409. data/vendor/tomotopy/src/Utils/avx_mathfun.h +736 -0
  410. data/vendor/tomotopy/src/Utils/exception.h +28 -0
  411. data/vendor/tomotopy/src/Utils/math.h +281 -0
  412. data/vendor/tomotopy/src/Utils/rtnorm.hpp +2690 -0
  413. data/vendor/tomotopy/src/Utils/sample.hpp +192 -0
  414. data/vendor/tomotopy/src/Utils/serializer.hpp +695 -0
  415. data/vendor/tomotopy/src/Utils/slp.hpp +131 -0
  416. data/vendor/tomotopy/src/Utils/sse_gamma.h +48 -0
  417. data/vendor/tomotopy/src/Utils/sse_mathfun.h +710 -0
  418. data/vendor/tomotopy/src/Utils/text.hpp +49 -0
  419. data/vendor/tomotopy/src/Utils/tvector.hpp +543 -0
  420. metadata +531 -0
@@ -0,0 +1,192 @@
1
+ #pragma once
2
+
3
+ #include <random>
4
+ #ifdef __AVX__
5
+ #include <immintrin.h>
6
+ #elif defined(__SSE2__) || defined(_WIN64)
7
+ #include <xmmintrin.h>
8
+ #else
9
+
10
+ #endif
11
+
12
+ #ifdef _WIN32
13
+ #include <intrin.h>
14
+ #endif
15
+
16
+ namespace tomoto
17
+ {
18
+ namespace sample
19
+ {
20
+ #ifdef _WIN32
21
+ inline uint32_t popcnt(uint32_t i)
22
+ {
23
+ return __popcnt(i);
24
+ }
25
+
26
+ #ifdef _WIN64
27
+ inline uint64_t log2_ceil(uint64_t i)
28
+ {
29
+ return 64 - __lzcnt64(i) - ((i & (i - 1)) == 0 ? 1 : 0);
30
+ }
31
+ #else
32
+ inline uint32_t log2_ceil(uint32_t i)
33
+ {
34
+ return 32 - __lzcnt(i) - ((i & (i - 1)) == 0 ? 1 : 0);
35
+ }
36
+ #endif
37
+
38
+ #else
39
+ inline uint32_t popcnt(uint32_t i)
40
+ {
41
+ return __builtin_popcount(i);
42
+ }
43
+
44
+ #ifdef __x86_64
45
+ inline uint64_t log2_ceil(uint64_t i)
46
+ {
47
+ return 64 - __builtin_clzll(i) - ((i & (i - 1)) == 0 ? 1 : 0);
48
+ }
49
+ #else
50
+ inline uint32_t log2_ceil(uint32_t i)
51
+ {
52
+ return 32 - __builtin_clz(i) - ((i & (i - 1)) == 0 ? 1 : 0);
53
+ }
54
+ #endif
55
+
56
+ #endif
57
+
58
+
59
+ #if defined(__SSE2__) || defined(_WIN64)
60
+ inline __m128 scan_SSE(__m128 x)
61
+ {
62
+ x = _mm_add_ps(x, _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(x), 4)));
63
+ x = _mm_add_ps(x, _mm_castsi128_ps(_mm_slli_si128(_mm_castps_si128(x), 8)));
64
+ return x;
65
+ }
66
+
67
+ inline void prefixSum(float* arr, int n)
68
+ {
69
+ int n4 = n & ~3;
70
+ __m128 offset = _mm_setzero_ps();
71
+ for (int i = 0; i < n4; i += 4)
72
+ {
73
+ __m128 x = _mm_load_ps(&arr[i]);
74
+ __m128 out = scan_SSE(x);
75
+ out = _mm_add_ps(out, offset);
76
+ _mm_store_ps(&arr[i], out);
77
+ offset = _mm_shuffle_ps(out, out, _MM_SHUFFLE(3, 3, 3, 3));
78
+ }
79
+ if (!n4) n4 = 1;
80
+ for (size_t i = n4; i < n; ++i)
81
+ {
82
+ arr[i] += arr[i - 1];
83
+ }
84
+ }
85
+ #else
86
+ inline void prefixSum(float* arr, int n)
87
+ {
88
+ int n4 = n & ~3;
89
+ float acc = 0;
90
+ for (int i = 0; i < n4; i += 4)
91
+ {
92
+ // first accumulation
93
+ arr[i + 3] += arr[i + 2];
94
+ arr[i + 2] += arr[i + 1];
95
+ arr[i + 1] += arr[i];
96
+
97
+ // second accumulation
98
+ arr[i + 3] += arr[i + 1];
99
+ arr[i + 2] += arr[i];
100
+
101
+ // accumulate offset
102
+ arr[i] += acc;
103
+ arr[i + 1] += acc;
104
+ arr[i + 2] += acc;
105
+ arr[i + 3] += acc;
106
+
107
+ acc = arr[i + 3];
108
+ }
109
+
110
+ if (!n4) n4 = 1;
111
+ for (size_t i = n4; i < n; ++i)
112
+ {
113
+ arr[i] += arr[i - 1];
114
+ }
115
+ }
116
+ #endif
117
+
118
+ template<class RealIt, class Random>
119
+ inline size_t sampleFromDiscrete(RealIt begin, RealIt end, Random& rg)
120
+ {
121
+ auto r = rg.uniform_real() * std::accumulate(begin, end, 0.f);
122
+ size_t K = std::distance(begin, end);
123
+ size_t z = 0;
124
+ for (; r > *begin && z < K - 1; ++z, ++begin)
125
+ {
126
+ r -= *begin;
127
+ }
128
+ return z;
129
+ }
130
+
131
+ template<class RealIt, class Random>
132
+ inline size_t sampleFromDiscreteAcc(RealIt begin, RealIt end, Random& rg)
133
+ {
134
+ auto r = rg.uniform_real() * *(end - 1);
135
+ size_t K = std::distance(begin, end);
136
+ size_t z = 0;
137
+ #ifdef __AVX__
138
+ __m256 mr = _mm256_set1_ps(r), mz;
139
+ int mask;
140
+ for (; z < (K >> 5) << 5; z += 32)
141
+ {
142
+ mz = _mm256_load_ps(&begin[z]);
143
+ mask = _mm256_movemask_ps(_mm256_cmp_ps(mr, mz, _CMP_LT_OQ));
144
+ if (mask) return z + 8 - popcnt(mask);
145
+ mz = _mm256_load_ps(&begin[z + 8]);
146
+ mask = _mm256_movemask_ps(_mm256_cmp_ps(mr, mz, _CMP_LT_OQ));
147
+ if (mask) return z + 16 - popcnt(mask);
148
+ mz = _mm256_load_ps(&begin[z + 16]);
149
+ mask = _mm256_movemask_ps(_mm256_cmp_ps(mr, mz, _CMP_LT_OQ));
150
+ if (mask) return z + 24 - popcnt(mask);
151
+ mz = _mm256_load_ps(&begin[z + 24]);
152
+ mask = _mm256_movemask_ps(_mm256_cmp_ps(mr, mz, _CMP_LT_OQ));
153
+ if (mask) return z + 32 - popcnt(mask);
154
+ }
155
+ for (; z < (K >> 3) << 3; z += 8)
156
+ {
157
+ __m256 mz = _mm256_load_ps(&begin[z]);
158
+ int mask = _mm256_movemask_ps(_mm256_cmp_ps(mr, mz, _CMP_LT_OQ));
159
+ if (mask) return z + 8 - popcnt(mask);
160
+ }
161
+ #elif defined(__SSE2__)
162
+ __m128 mr = _mm_set1_ps(r);
163
+ for (; z < (K >> 2) << 2; z += 4)
164
+ {
165
+ __m128 mz = _mm_load_ps(&begin[z]);
166
+ int mask = _mm_movemask_ps(_mm_cmplt_ps(mr, mz));
167
+ if (mask) return z + 4 - popcnt(mask);
168
+ }
169
+ #else
170
+ for (; z < (K >> 3) << 3; z += 8)
171
+ {
172
+ if (r < begin[z]) return z;
173
+ if (r < begin[z + 1]) return z + 1;
174
+ if (r < begin[z + 2]) return z + 2;
175
+ if (r < begin[z + 3]) return z + 3;
176
+ if (r < begin[z + 4]) return z + 4;
177
+ if (r < begin[z + 5]) return z + 5;
178
+ if (r < begin[z + 6]) return z + 6;
179
+ if (r < begin[z + 7]) return z + 7;
180
+ }
181
+ #endif
182
+ for (; z < K; ++z)
183
+ {
184
+ if (r < begin[z]) return z;
185
+ }
186
+ return K - 1;
187
+ }
188
+ }
189
+ }
190
+
191
+ #include "AliasMethod.hpp"
192
+
@@ -0,0 +1,695 @@
1
+ #pragma once
2
+ #include <iostream>
3
+ #include <memory>
4
+ #include <string>
5
+ #include <array>
6
+ #include <type_traits>
7
+ #include <Eigen/Dense>
8
+ #include <vector>
9
+ #include "tvector.hpp"
10
+ #include "text.hpp"
11
+
12
+ /*
13
+
14
+ A new serializer format for tomotopy 0.6.0
15
+
16
+ struct TaggedData
17
+ {
18
+ char[4] magic_id;
19
+ uint16_t major_version, minor_version;
20
+ uint64_t tot_size;
21
+ uint32_t key_size, trailing_data_cnt;
22
+ char[key_size] key;
23
+ char[...] data;
24
+ }
25
+
26
+ */
27
+
28
+ namespace tomoto
29
+ {
30
+ namespace serializer
31
+ {
32
+ namespace detail
33
+ {
34
+ template<class _T> using Invoke = typename _T::type;
35
+
36
+ template<size_t...> struct seq { using type = seq; };
37
+
38
+ template<class _S1, class _S2> struct concat;
39
+
40
+ template<size_t... _i1, size_t... _i2>
41
+ struct concat<seq<_i1...>, seq<_i2...>>
42
+ : seq<_i1..., (sizeof...(_i1) + _i2)...> {};
43
+
44
+ template<class _S1, class _S2>
45
+ using Concat = Invoke<concat<_S1, _S2>>;
46
+
47
+ template<size_t _n> struct gen_seq;
48
+ template<size_t _n> using GenSeq = Invoke<gen_seq<_n>>;
49
+
50
+ template<size_t _n>
51
+ struct gen_seq : Concat<GenSeq<_n / 2>, GenSeq<_n - _n / 2>> {};
52
+
53
+ template<> struct gen_seq<0> : seq<> {};
54
+ template<> struct gen_seq<1> : seq<0> {};
55
+
56
+ template <size_t _n, size_t ... _is>
57
+ std::array<char, _n - 1> to_array(const char(&a)[_n], seq<_is...>)
58
+ {
59
+ return { {a[_is]...} };
60
+ }
61
+
62
+ template <size_t _n>
63
+ constexpr std::array<char, _n - 1> to_array(const char(&a)[_n])
64
+ {
65
+ return to_array(a, GenSeq<_n - 1>{});
66
+ }
67
+
68
+ template <size_t _n, size_t ... _is>
69
+ std::array<char, _n> to_arrayz(const char(&a)[_n], seq<_is...>)
70
+ {
71
+ return { {a[_is]..., 0} };
72
+ }
73
+
74
+ template <size_t _n>
75
+ constexpr std::array<char, _n> to_arrayz(const char(&a)[_n])
76
+ {
77
+ return to_arrayz(a, GenSeq<_n - 1>{});
78
+ }
79
+ }
80
+
81
+ template<typename _Ty> inline void writeToStream(std::ostream& ostr, const _Ty& v);
82
+ template<typename _Ty> inline void readFromStream(std::istream& istr, _Ty& v);
83
+ template<typename _Ty> inline _Ty readFromStream(std::istream& istr);
84
+
85
+ class UnfitException : public std::ios_base::failure
86
+ {
87
+ using std::ios_base::failure::failure;
88
+ };
89
+
90
+ template<size_t _len>
91
+ struct Key
92
+ {
93
+ std::array<char, _len> m;
94
+
95
+ std::string str() const
96
+ {
97
+ return std::string{ m.begin(), m.end() };
98
+ }
99
+
100
+ Key(const std::array<char, _len>& _m) : m(_m)
101
+ {
102
+ }
103
+
104
+ Key(std::array<char, _len>&& _m) : m(_m)
105
+ {
106
+ }
107
+
108
+ Key(const char(&a)[_len + 1]) : Key{ detail::to_array(a) }
109
+ {
110
+ }
111
+ };
112
+
113
+ template<typename _Ty>
114
+ struct is_key : public std::false_type
115
+ {
116
+ };
117
+
118
+ template<size_t _len>
119
+ struct is_key<Key<_len>> : public std::true_type
120
+ {
121
+ };
122
+
123
+ template<size_t _n>
124
+ constexpr Key<_n - 1> to_key(const char(&a)[_n])
125
+ {
126
+ return Key<_n - 1>{detail::to_array(a)};
127
+ }
128
+
129
+ template<size_t _n>
130
+ constexpr Key<_n> to_keyz(const char(&a)[_n])
131
+ {
132
+ return Key<_n>{detail::to_arrayz(a)};
133
+ }
134
+
135
+ inline void writeMany(std::ostream& ostr)
136
+ {
137
+ // do nothing
138
+ }
139
+
140
+ template<typename _FirstTy, typename ... _RestTy>
141
+ inline typename std::enable_if<!is_key<_FirstTy>::value>::type writeMany(std::ostream& ostr, const _FirstTy& first, _RestTy&&... rest)
142
+ {
143
+ writeToStream(ostr, first);
144
+ writeMany(ostr, std::forward<_RestTy>(rest)...);
145
+ }
146
+
147
+ template<size_t _len, typename ... _RestTy>
148
+ inline void writeMany(std::ostream& ostr, const Key<_len>& first, _RestTy&&... rest)
149
+ {
150
+ ostr.write(first.m.data(), first.m.size());
151
+ writeMany(ostr, std::forward<_RestTy>(rest)...);
152
+ }
153
+
154
+ inline void readMany(std::istream& istr)
155
+ {
156
+ // do nothing
157
+ }
158
+
159
+ template<typename _FirstTy, typename ... _RestTy>
160
+ inline typename std::enable_if<!is_key<_FirstTy>::value>::type readMany(std::istream& istr, _FirstTy& first, _RestTy&&... rest)
161
+ {
162
+ readFromStream(istr, first);
163
+ readMany(istr, std::forward<_RestTy>(rest)...);
164
+ }
165
+
166
+ template<size_t _len, typename ... _RestTy>
167
+ inline void readMany(std::istream& istr, const Key<_len>& first, _RestTy&&... rest)
168
+ {
169
+ std::array<char, _len> m;
170
+ istr.read(m.data(), m.size());
171
+ if (m != first.m)
172
+ {
173
+ throw UnfitException(std::string("'") + first.str() + std::string("' is needed but '") + std::string{ m.begin(), m.end() } +std::string("'"));
174
+ }
175
+ readMany(istr, std::forward<_RestTy>(rest)...);
176
+ }
177
+
178
+ template<size_t _len>
179
+ inline bool readTest(std::istream& istr, const Key<_len>& first)
180
+ {
181
+ std::array<char, _len> m;
182
+ istr.read(m.data(), m.size());
183
+ return m == first.m;
184
+ }
185
+
186
+ template<size_t>
187
+ struct version_holder {};
188
+
189
+ namespace detail
190
+ {
191
+ template<typename _Class, typename _RetTy, typename ..._Args>
192
+ _RetTy test_mf(_RetTy(_Class::*mf)(_Args...))
193
+ {
194
+ return _RetTy{};
195
+ }
196
+
197
+ template<typename _Class, typename _RetTy, typename ..._Args>
198
+ _RetTy test_mf_c(_RetTy(_Class::*mf)(_Args...) const)
199
+ {
200
+ return _RetTy{};
201
+ }
202
+
203
+ template<typename> struct sfinae_true : std::true_type {};
204
+ template<typename _Ty>
205
+ static auto testSave(int)->sfinae_true<decltype(test_mf_c<_Ty, void, std::ostream&>(&_Ty::serializerWrite))>;
206
+ template<typename _Ty>
207
+ static auto testSave(long)->std::false_type;
208
+
209
+ template<typename _Ty>
210
+ static auto testLoad(int)->sfinae_true<decltype(test_mf<_Ty, void, std::istream&>(&_Ty::serializerRead))>;
211
+ template<typename _Ty>
212
+ static auto testLoad(long)->std::false_type;
213
+
214
+ template<typename _Ty, size_t _version>
215
+ static auto testSaveV(int)->sfinae_true<decltype(test_mf_c<_Ty, void, version_holder<_version>, std::ostream&>(&_Ty::serializerWrite))>;
216
+ template<typename _Ty, size_t _version>
217
+ static auto testSaveV(long)->std::false_type;
218
+
219
+ template<typename _Ty, size_t _version>
220
+ static auto testLoadV(int)->sfinae_true<decltype(test_mf<_Ty, void, version_holder<_version>, std::istream&>(&_Ty::serializerRead))>;
221
+ template<typename _Ty, size_t _version>
222
+ static auto testLoadV(long)->std::false_type;
223
+ }
224
+ template<typename _Ty>
225
+ struct hasSave : decltype(detail::testSave<_Ty>(0)){};
226
+
227
+ template<typename _Ty>
228
+ struct hasLoad : decltype(detail::testLoad<_Ty>(0)){};
229
+
230
+ template<typename _Ty, size_t _version>
231
+ struct hasSaveV : decltype(detail::testSaveV<_Ty, _version>(0)){};
232
+
233
+ template<typename _Ty, size_t _version>
234
+ struct hasLoadV : decltype(detail::testLoadV<_Ty, _version>(0)){};
235
+
236
+ template<class _Ty>
237
+ inline typename std::enable_if<std::is_fundamental<_Ty>::value>::type writeToBinStreamImpl(std::ostream& ostr, const _Ty& v)
238
+ {
239
+ if (!ostr.write((const char*)&v, sizeof(_Ty)))
240
+ throw std::ios_base::failure(std::string("writing type '") + typeid(_Ty).name() + std::string("' is failed") );
241
+ }
242
+
243
+ template<class _Ty>
244
+ inline typename std::enable_if<std::is_fundamental<_Ty>::value>::type readFromBinStreamImpl(std::istream& istr, _Ty& v)
245
+ {
246
+ if (!istr.read((char*)&v, sizeof(_Ty)))
247
+ throw std::ios_base::failure(std::string("reading type '") + typeid(_Ty).name() + std::string("' is failed") );
248
+ }
249
+
250
+ template<class _Ty>
251
+ inline typename std::enable_if<hasSave<_Ty>::value>::type writeToBinStreamImpl(std::ostream& ostr, const _Ty& v)
252
+ {
253
+ v.serializerWrite(ostr);
254
+ }
255
+
256
+ template<class _Ty, size_t _version = 0>
257
+ inline typename std::enable_if<
258
+ hasSaveV<_Ty, _version>::value && !hasSaveV<_Ty, _version + 1>::value
259
+ >::type writeToBinStreamImpl(std::ostream& ostr, const _Ty& v)
260
+ {
261
+ v.serializerWrite(version_holder<_version>{}, ostr);
262
+ }
263
+
264
+ template<class _Ty, size_t _version = 0>
265
+ inline typename std::enable_if<
266
+ hasSaveV<_Ty, _version>::value && hasSaveV<_Ty, _version + 1>::value
267
+ >::type writeToBinStreamImpl(std::ostream& ostr, const _Ty& v)
268
+ {
269
+ return writeToBinStreamImpl<_Ty, _version + 1>(ostr, v);
270
+ }
271
+
272
+ template<class _Ty>
273
+ inline typename std::enable_if<hasLoad<_Ty>::value>::type readFromBinStreamImpl(std::istream& istr, _Ty& v)
274
+ {
275
+ v.serializerRead(istr);
276
+ }
277
+
278
+ template<class _Ty, size_t _version = 0>
279
+ inline typename std::enable_if<
280
+ hasLoadV<_Ty, _version>::value && !hasLoadV<_Ty, _version + 1>::value
281
+ >::type readFromBinStreamImpl(std::istream& istr, _Ty& v)
282
+ {
283
+ v.serializerRead(version_holder<_version>{}, istr);
284
+ }
285
+
286
+ template<class _Ty, size_t _version = 0>
287
+ inline typename std::enable_if<
288
+ hasLoadV<_Ty, _version>::value && hasLoadV<_Ty, _version + 1>::value
289
+ >::type readFromBinStreamImpl(std::istream& istr, _Ty& v)
290
+ {
291
+ auto pos = istr.tellg();
292
+ try
293
+ {
294
+ // try higher version first
295
+ return readFromBinStreamImpl<_Ty, _version + 1>(istr, v);
296
+ }
297
+ catch (const std::ios_base::failure&)
298
+ {
299
+ istr.seekg(pos);
300
+ // try current version if fails
301
+ v.serializerRead(version_holder<_version>{}, istr);
302
+ }
303
+ }
304
+
305
+ template<class _Ty>
306
+ inline void writeToBinStreamImpl(std::ostream& ostr, const Eigen::Matrix<_Ty, -1, -1>& v)
307
+ {
308
+ writeToStream<uint32_t>(ostr, (uint32_t)v.rows());
309
+ writeToStream<uint32_t>(ostr, (uint32_t)v.cols());
310
+ if (!ostr.write((const char*)v.data(), sizeof(_Ty) * v.size()))
311
+ throw std::ios_base::failure( std::string("writing type '") + typeid(_Ty).name() + std::string("' is failed") );
312
+ }
313
+
314
+ template<class _Ty>
315
+ inline void readFromBinStreamImpl(std::istream& istr, Eigen::Matrix<_Ty, -1, -1>& v)
316
+ {
317
+ uint32_t rows = readFromStream<uint32_t>(istr);
318
+ uint32_t cols = readFromStream<uint32_t>(istr);
319
+ v = Eigen::Matrix<_Ty, -1, -1>::Zero(rows, cols);
320
+ if (!istr.read((char*)v.data(), sizeof(_Ty) * rows * cols))
321
+ throw std::ios_base::failure( std::string("reading type '") + typeid(_Ty).name() + std::string("' is failed") );
322
+ }
323
+
324
+ template<class _Ty>
325
+ inline void writeToBinStreamImpl(std::ostream& ostr, const Eigen::Matrix<_Ty, -1, 1>& v)
326
+ {
327
+ writeToStream<uint32_t>(ostr, (uint32_t)v.rows());
328
+ writeToStream<uint32_t>(ostr, (uint32_t)v.cols());
329
+ if (!ostr.write((const char*)v.data(), sizeof(_Ty) * v.size()))
330
+ throw std::ios_base::failure( std::string("writing type '") + typeid(_Ty).name() + std::string("' is failed") );
331
+ }
332
+
333
+ template<class _Ty>
334
+ inline void readFromBinStreamImpl(std::istream& istr, Eigen::Matrix<_Ty, -1, 1>& v)
335
+ {
336
+ uint32_t rows = readFromStream<uint32_t>(istr);
337
+ uint32_t cols = readFromStream<uint32_t>(istr);
338
+ if (cols != 1) throw std::ios_base::failure( "matrix cols != 1'" );
339
+ v = Eigen::Matrix<_Ty, -1, 1>::Zero(rows);
340
+ if (!istr.read((char*)v.data(), sizeof(_Ty) * rows * cols))
341
+ throw std::ios_base::failure( std::string("reading type '") + typeid(_Ty).name() + std::string("' is failed") );
342
+ }
343
+
344
+ template<class _Ty>
345
+ inline void writeToBinStreamImpl(std::ostream& ostr, const std::vector<_Ty>& v)
346
+ {
347
+ writeToStream<uint32_t>(ostr, (uint32_t)v.size());
348
+ for (auto& e : v) writeToStream(ostr, e);
349
+ }
350
+
351
+ template<class _Ty>
352
+ inline void readFromBinStreamImpl(std::istream& istr, std::vector<_Ty>& v)
353
+ {
354
+ uint32_t size = readFromStream<uint32_t>(istr);
355
+ v.resize(size);
356
+ for (auto& e : v) readFromStream(istr, e);
357
+ }
358
+
359
+ template<class _Ty1, class _Ty2>
360
+ inline void writeToBinStreamImpl(std::ostream& ostr, const std::pair<_Ty1, _Ty2>& v)
361
+ {
362
+ writeToStream(ostr, v.first);
363
+ writeToStream(ostr, v.second);
364
+ }
365
+
366
+ template<class _Ty1, class _Ty2>
367
+ inline void readFromBinStreamImpl(std::istream& istr, std::pair<_Ty1, _Ty2>& v)
368
+ {
369
+ readFromStream(istr, v.first);
370
+ readFromStream(istr, v.second);
371
+ }
372
+
373
+ template<class _KeyTy, class _ValTy>
374
+ inline void writeToBinStreamImpl(std::ostream& ostr, const std::unordered_map<_KeyTy, _ValTy>& v)
375
+ {
376
+ writeToStream<uint32_t>(ostr, (uint32_t)v.size());
377
+ for (auto& e : v) writeToStream(ostr, e);
378
+ }
379
+
380
+ template<class _KeyTy, class _ValTy>
381
+ inline void readFromBinStreamImpl(std::istream& istr, std::unordered_map<_KeyTy, _ValTy>& v)
382
+ {
383
+ uint32_t size = readFromStream<uint32_t>(istr);
384
+ v.clear();
385
+ for (size_t i = 0; i < size; ++i)
386
+ {
387
+ v.emplace(readFromStream<std::pair<_KeyTy, _ValTy>>(istr));
388
+ }
389
+ }
390
+
391
+ template<class _Ty, size_t _N>
392
+ inline void writeToBinStreamImpl(std::ostream& ostr, const std::array<_Ty, _N>& v)
393
+ {
394
+ writeToStream<uint32_t>(ostr, (uint32_t)v.size());
395
+ for (auto& e : v) writeToStream(ostr, e);
396
+ }
397
+
398
+ template<class _Ty, size_t _N>
399
+ inline void readFromBinStreamImpl(std::istream& istr, std::array<_Ty, _N>& v)
400
+ {
401
+ uint32_t size = readFromStream<uint32_t>(istr);
402
+ if (_N != size) throw std::ios_base::failure( text::format("the size of array must be %zd, not %zd", _N, size) );
403
+ for (auto& e : v) readFromStream(istr, e);
404
+ }
405
+
406
+ template<class _Ty>
407
+ inline void writeToBinStreamImpl(std::ostream& ostr, const tvector<_Ty>& v)
408
+ {
409
+ writeToStream<uint32_t>(ostr, (uint32_t)v.size());
410
+ for (auto& e : v) writeToStream(ostr, e);
411
+ }
412
+
413
+ template<class _Ty>
414
+ inline void readFromBinStreamImpl(std::istream& istr, tvector<_Ty>& v)
415
+ {
416
+ uint32_t size = readFromStream<uint32_t>(istr);
417
+ v.resize(size);
418
+ for (auto& e : v) readFromStream(istr, e);
419
+ }
420
+
421
+ template<class _Ty>
422
+ inline void writeToBinStreamImpl(std::ostream& ostr, const std::basic_string<_Ty>& v)
423
+ {
424
+ writeToStream<uint32_t>(ostr, (uint32_t)v.size());
425
+ if (!ostr.write((const char*)v.data(), sizeof(_Ty) * v.size()))
426
+ throw std::ios_base::failure( std::string("writing type '") + typeid(_Ty).name() + std::string("' is failed") );
427
+ }
428
+
429
+ template<class _Ty>
430
+ inline void readFromBinStreamImpl(std::istream& istr, std::basic_string<_Ty>& v)
431
+ {
432
+ uint32_t size = readFromStream<uint32_t>(istr);
433
+ v.resize(size);
434
+ if (!istr.read((char*)v.data(), sizeof(_Ty) * v.size()))
435
+ throw std::ios_base::failure( std::string("reading type '") + typeid(_Ty).name() + std::string("' is failed") );
436
+ }
437
+
438
+ template<class _Ty>
439
+ inline typename std::enable_if<std::is_abstract<_Ty>::value>::type writeToBinStreamImpl(std::ostream& ostr, const std::unique_ptr<_Ty>& v)
440
+ {
441
+ _Ty::serializerWrite(v, ostr);
442
+ }
443
+
444
+ template<class _Ty>
445
+ inline typename std::enable_if<std::is_abstract<_Ty>::value>::type readFromBinStreamImpl(std::istream& istr, std::unique_ptr<_Ty>& v)
446
+ {
447
+ _Ty::serializerRead(v, istr);
448
+ }
449
+
450
+ template<typename _Ty>
451
+ inline void writeToStream(std::ostream& ostr, const _Ty& v)
452
+ {
453
+ return writeToBinStreamImpl(ostr, v);
454
+ }
455
+
456
+ template<typename _Ty>
457
+ inline void readFromStream(std::istream& istr, _Ty& v)
458
+ {
459
+ return readFromBinStreamImpl(istr, v);
460
+ }
461
+
462
+ template<typename _Ty>
463
+ inline _Ty readFromStream(std::istream& istr)
464
+ {
465
+ _Ty v;
466
+ readFromBinStreamImpl(istr, v);
467
+ return v;
468
+ }
469
+
470
+ static auto taggedDataKey = to_key("TPTK");
471
+
472
+ template<size_t _len, typename _Ty>
473
+ inline void writeTaggedData(std::ostream& ostr, uint32_t version, uint32_t trailing_cnt, const Key<_len>& key, const _Ty& data)
474
+ {
475
+ uint16_t major = version >> 16, minor = version & 0xFFFF;
476
+ writeMany(ostr, taggedDataKey, version);
477
+ std::streampos totsize_pos = ostr.tellp();
478
+ writeMany(ostr, (uint64_t)0, (uint32_t)_len, trailing_cnt, key, data);
479
+ std::streampos end_pos = ostr.tellp();
480
+ ostr.seekp(totsize_pos);
481
+ writeMany(ostr, (uint64_t)(end_pos - totsize_pos));
482
+ ostr.seekp(end_pos);
483
+ }
484
+
485
+ template<size_t _len, typename _Ty>
486
+ inline std::pair<bool, std::streampos> readTaggedData(std::istream& istr, uint32_t version, uint32_t& trailing_cnt, const Key<_len>& key, _Ty& data)
487
+ {
488
+ uint16_t major = version >> 16, minor = version & 0xFFFF;
489
+ uint64_t totsize;
490
+ uint32_t keysize;
491
+ std::streampos start_pos = istr.tellg();
492
+ readMany(istr, taggedDataKey, version);
493
+ std::streampos totsize_pos = istr.tellg();
494
+ readMany(istr, totsize, keysize, trailing_cnt);
495
+ std::streampos end_pos = totsize_pos + (std::streamoff)totsize;
496
+ if (_len != keysize)
497
+ {
498
+ istr.seekg(start_pos);
499
+ return std::make_pair(false, end_pos);
500
+ }
501
+
502
+ if (!readTest(istr, key))
503
+ {
504
+ istr.seekg(start_pos);
505
+ return std::make_pair(false, end_pos);
506
+ }
507
+
508
+ readMany(istr, data);
509
+ if (end_pos != istr.tellg())
510
+ {
511
+ istr.seekg(start_pos);
512
+ return std::make_pair(false, end_pos);
513
+ }
514
+ return std::make_pair(true, end_pos);
515
+ }
516
+
517
+ inline void readTaggedMany(std::istream& istr, uint32_t version)
518
+ {
519
+ // seek to the end of tagged data list
520
+ uint32_t trailing_cnt;
521
+ do
522
+ {
523
+ uint64_t totsize;
524
+ uint32_t keysize;
525
+ readMany(istr, taggedDataKey, version);
526
+ std::streampos totsize_pos = istr.tellg();
527
+ readMany(istr, totsize, keysize, trailing_cnt);
528
+ istr.seekg(totsize_pos + (std::streamoff)totsize);
529
+
530
+ } while (trailing_cnt);
531
+ }
532
+
533
+ template<size_t _len, typename _Ty, typename ... _Rest>
534
+ inline void readTaggedMany(std::istream& istr, uint32_t version, const Key<_len>& key, _Ty& data, _Rest&&... rest)
535
+ {
536
+ auto start_pos = istr.tellg();
537
+ uint32_t trailing_cnt;
538
+ do
539
+ {
540
+ std::pair<bool, std::streampos> p = readTaggedData(istr, version, trailing_cnt, key, data);
541
+ if (p.first)
542
+ {
543
+ break;
544
+ }
545
+ else
546
+ {
547
+ istr.seekg(p.second);
548
+ }
549
+ } while (trailing_cnt);
550
+
551
+ istr.seekg(start_pos);
552
+ readTaggedMany(istr, version, std::forward<_Rest>(rest)...);
553
+ }
554
+
555
+ inline void writeTaggedMany(std::ostream& ostr, uint32_t version)
556
+ {
557
+ // do nothing
558
+ }
559
+
560
+ template<size_t _len, typename _Ty, typename ... _Rest>
561
+ inline void writeTaggedMany(std::ostream& ostr, uint32_t version, const Key<_len>& key, const _Ty& data, _Rest&&... rest)
562
+ {
563
+ writeTaggedData(ostr, version, sizeof...(_Rest) / 2, key, data);
564
+ writeTaggedMany(ostr, version, std::forward<_Rest>(rest)...);
565
+ }
566
+ }
567
+ }
568
+
569
+ #define DEFINE_SERIALIZER(...) void serializerRead(std::istream& istr)\
570
+ {\
571
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
572
+ }\
573
+ void serializerWrite(std::ostream& ostr) const\
574
+ {\
575
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
576
+ }
577
+
578
+ #define DEFINE_SERIALIZER_WITH_VERSION(v,...) void serializerRead(tomoto::serializer::version_holder<v>, std::istream& istr)\
579
+ {\
580
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
581
+ }\
582
+ void serializerWrite(tomoto::serializer::version_holder<v>, std::ostream& ostr) const\
583
+ {\
584
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
585
+ }
586
+
587
+ #define DEFINE_SERIALIZER_CALLBACK(onRead, ...) void serializerRead(std::istream& istr)\
588
+ {\
589
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
590
+ this->onRead();\
591
+ }\
592
+ void serializerWrite(std::ostream& ostr) const\
593
+ {\
594
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
595
+ }
596
+
597
+ #define DEFINE_SERIALIZER_AFTER_BASE(base, ...) void serializerRead(std::istream& istr)\
598
+ {\
599
+ base::serializerRead(istr);\
600
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
601
+ }\
602
+ void serializerWrite(std::ostream& ostr) const\
603
+ {\
604
+ base::serializerWrite(ostr);\
605
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
606
+ }
607
+
608
+ #define DEFINE_SERIALIZER_AFTER_BASE_WITH_VERSION(base, v, ...) void serializerRead(tomoto::serializer::version_holder<v> _v, std::istream& istr)\
609
+ {\
610
+ base::serializerRead(_v, istr);\
611
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
612
+ }\
613
+ void serializerWrite(tomoto::serializer::version_holder<v> _v, std::ostream& ostr) const\
614
+ {\
615
+ base::serializerWrite(_v, ostr);\
616
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
617
+ }
618
+
619
+ #define DEFINE_SERIALIZER_BASE_WITH_VERSION(base, v) void serializerRead(tomoto::serializer::version_holder<v> _v, std::istream& istr)\
620
+ {\
621
+ base::serializerRead(_v, istr);\
622
+ }\
623
+ void serializerWrite(tomoto::serializer::version_holder<v> _v, std::ostream& ostr) const\
624
+ {\
625
+ base::serializerWrite(_v, ostr);\
626
+ }
627
+
628
+ #define DEFINE_SERIALIZER_AFTER_BASE_CALLBACK(base, onRead, ...) void serializerRead(std::istream& istr)\
629
+ {\
630
+ base::serializerRead(istr);\
631
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
632
+ this->onRead();\
633
+ }\
634
+ void serializerWrite(std::ostream& ostr) const\
635
+ {\
636
+ base::serializerWrite(ostr);\
637
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
638
+ }
639
+
640
+ #define DEFINE_SERIALIZER_AFTER_BASE2_CALLBACK(base1, base2, onRead, ...) void serializerRead(std::istream& istr)\
641
+ {\
642
+ base1, base2::serializerRead(istr);\
643
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
644
+ this->onRead();\
645
+ }\
646
+ void serializerWrite(std::ostream& ostr) const\
647
+ {\
648
+ base1, base2::serializerWrite(ostr);\
649
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
650
+ }
651
+
652
+ #define DEFINE_SERIALIZER_VIRTUAL(...) virtual void serializerRead(std::istream& istr)\
653
+ {\
654
+ tomoto::serializer::readMany(istr, __VA_ARGS__);\
655
+ }\
656
+ virtual void serializerWrite(std::ostream& ostr) const\
657
+ {\
658
+ tomoto::serializer::writeMany(ostr, __VA_ARGS__);\
659
+ }
660
+
661
+ #define _TO_KEY_VALUE_0()
662
+ #define _TO_KEY_VALUE_1(a) tomoto::serializer::to_keyz(#a), a
663
+ #define _TO_KEY_VALUE_2(a, b) _TO_KEY_VALUE_1(a), _TO_KEY_VALUE_1(b)
664
+ #define _TO_KEY_VALUE_3(a, b, c) _TO_KEY_VALUE_2(a, b), _TO_KEY_VALUE_1(c)
665
+ #define _TO_KEY_VALUE_4(a, b, c, d) _TO_KEY_VALUE_2(a, b), _TO_KEY_VALUE_2(c, d)
666
+ #define _TO_KEY_VALUE_5(a, b, c, d, e) _TO_KEY_VALUE_3(a, b, c), _TO_KEY_VALUE_2(d, e)
667
+ #define _TO_KEY_VALUE_6(a, b, c, d, e, f) _TO_KEY_VALUE_3(a, b, c), _TO_KEY_VALUE_3(d, e, f)
668
+ #define _TO_KEY_VALUE_7(a, b, c, d, e, f, g) _TO_KEY_VALUE_4(a, b, c, d), _TO_KEY_VALUE_3(e, f, g)
669
+ #define _TO_KEY_VALUE_8(a, b, c, d, e, f, g, h) _TO_KEY_VALUE_4(a, b, c, d), _TO_KEY_VALUE_4(e, f, g, h)
670
+ #define _TO_KEY_VALUE_9(a, b, c, d, e, f, g, h, i) _TO_KEY_VALUE_5(a, b, c, d, e), _TO_KEY_VALUE_4(f, g, h, i)
671
+ #define _TO_KEY_VALUE_10(a, b, c, d, e, f, g, h, i, j) _TO_KEY_VALUE_5(a, b, c, d, e), _TO_KEY_VALUE_5(f, g, h, i, j)
672
+
673
+ #define _EXPAND(x) x
674
+ #define _TO_KEY_VALUE_K(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) _TO_KEY_VALUE_ ## N
675
+ #define _TO_KEY_VALUE(...) _EXPAND( _TO_KEY_VALUE_K(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)( __VA_ARGS__ ) )
676
+
677
+ #define DEFINE_TAGGED_SERIALIZER_WITH_VERSION(v, t,...) void serializerRead(tomoto::serializer::version_holder<v>, std::istream& istr)\
678
+ {\
679
+ tomoto::serializer::readTaggedMany(istr, t, _TO_KEY_VALUE(__VA_ARGS__));\
680
+ }\
681
+ void serializerWrite(tomoto::serializer::version_holder<v>, std::ostream& ostr) const\
682
+ {\
683
+ tomoto::serializer::writeTaggedMany(ostr, t, _TO_KEY_VALUE(__VA_ARGS__));\
684
+ }
685
+
686
+ #define DEFINE_TAGGED_SERIALIZER_AFTER_BASE_WITH_VERSION(base, v, t,...) void serializerRead(tomoto::serializer::version_holder<v> _v, std::istream& istr)\
687
+ {\
688
+ base::serializerRead(_v, istr);\
689
+ tomoto::serializer::readTaggedMany(istr, t, _TO_KEY_VALUE(__VA_ARGS__));\
690
+ }\
691
+ void serializerWrite(tomoto::serializer::version_holder<v> _v, std::ostream& ostr) const\
692
+ {\
693
+ base::serializerWrite(_v, ostr);\
694
+ tomoto::serializer::writeTaggedMany(ostr, t, _TO_KEY_VALUE(__VA_ARGS__));\
695
+ }