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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/ext/tomoto/ext.cpp +245 -0
- data/ext/tomoto/extconf.rb +28 -0
- data/lib/tomoto.rb +12 -0
- data/lib/tomoto/ct.rb +11 -0
- data/lib/tomoto/hdp.rb +11 -0
- data/lib/tomoto/lda.rb +67 -0
- data/lib/tomoto/version.rb +3 -0
- data/vendor/EigenRand/EigenRand/Core.h +1139 -0
- data/vendor/EigenRand/EigenRand/Dists/Basic.h +111 -0
- data/vendor/EigenRand/EigenRand/Dists/Discrete.h +877 -0
- data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +108 -0
- data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +626 -0
- data/vendor/EigenRand/EigenRand/EigenRand +19 -0
- data/vendor/EigenRand/EigenRand/Macro.h +24 -0
- data/vendor/EigenRand/EigenRand/MorePacketMath.h +978 -0
- data/vendor/EigenRand/EigenRand/PacketFilter.h +286 -0
- data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +624 -0
- data/vendor/EigenRand/EigenRand/RandUtils.h +413 -0
- data/vendor/EigenRand/EigenRand/doc.h +220 -0
- data/vendor/EigenRand/LICENSE +21 -0
- data/vendor/EigenRand/README.md +288 -0
- data/vendor/eigen/COPYING.BSD +26 -0
- data/vendor/eigen/COPYING.GPL +674 -0
- data/vendor/eigen/COPYING.LGPL +502 -0
- data/vendor/eigen/COPYING.MINPACK +52 -0
- data/vendor/eigen/COPYING.MPL2 +373 -0
- data/vendor/eigen/COPYING.README +18 -0
- data/vendor/eigen/Eigen/CMakeLists.txt +19 -0
- data/vendor/eigen/Eigen/Cholesky +46 -0
- data/vendor/eigen/Eigen/CholmodSupport +48 -0
- data/vendor/eigen/Eigen/Core +537 -0
- data/vendor/eigen/Eigen/Dense +7 -0
- data/vendor/eigen/Eigen/Eigen +2 -0
- data/vendor/eigen/Eigen/Eigenvalues +61 -0
- data/vendor/eigen/Eigen/Geometry +62 -0
- data/vendor/eigen/Eigen/Householder +30 -0
- data/vendor/eigen/Eigen/IterativeLinearSolvers +48 -0
- data/vendor/eigen/Eigen/Jacobi +33 -0
- data/vendor/eigen/Eigen/LU +50 -0
- data/vendor/eigen/Eigen/MetisSupport +35 -0
- data/vendor/eigen/Eigen/OrderingMethods +73 -0
- data/vendor/eigen/Eigen/PaStiXSupport +48 -0
- data/vendor/eigen/Eigen/PardisoSupport +35 -0
- data/vendor/eigen/Eigen/QR +51 -0
- data/vendor/eigen/Eigen/QtAlignedMalloc +40 -0
- data/vendor/eigen/Eigen/SPQRSupport +34 -0
- data/vendor/eigen/Eigen/SVD +51 -0
- data/vendor/eigen/Eigen/Sparse +36 -0
- data/vendor/eigen/Eigen/SparseCholesky +45 -0
- data/vendor/eigen/Eigen/SparseCore +69 -0
- data/vendor/eigen/Eigen/SparseLU +46 -0
- data/vendor/eigen/Eigen/SparseQR +37 -0
- data/vendor/eigen/Eigen/StdDeque +27 -0
- data/vendor/eigen/Eigen/StdList +26 -0
- data/vendor/eigen/Eigen/StdVector +27 -0
- data/vendor/eigen/Eigen/SuperLUSupport +64 -0
- data/vendor/eigen/Eigen/UmfPackSupport +40 -0
- data/vendor/eigen/Eigen/src/Cholesky/LDLT.h +673 -0
- data/vendor/eigen/Eigen/src/Cholesky/LLT.h +542 -0
- data/vendor/eigen/Eigen/src/Cholesky/LLT_LAPACKE.h +99 -0
- data/vendor/eigen/Eigen/src/CholmodSupport/CholmodSupport.h +639 -0
- data/vendor/eigen/Eigen/src/Core/Array.h +329 -0
- data/vendor/eigen/Eigen/src/Core/ArrayBase.h +226 -0
- data/vendor/eigen/Eigen/src/Core/ArrayWrapper.h +209 -0
- data/vendor/eigen/Eigen/src/Core/Assign.h +90 -0
- data/vendor/eigen/Eigen/src/Core/AssignEvaluator.h +935 -0
- data/vendor/eigen/Eigen/src/Core/Assign_MKL.h +178 -0
- data/vendor/eigen/Eigen/src/Core/BandMatrix.h +353 -0
- data/vendor/eigen/Eigen/src/Core/Block.h +452 -0
- data/vendor/eigen/Eigen/src/Core/BooleanRedux.h +164 -0
- data/vendor/eigen/Eigen/src/Core/CommaInitializer.h +160 -0
- data/vendor/eigen/Eigen/src/Core/ConditionEstimator.h +175 -0
- data/vendor/eigen/Eigen/src/Core/CoreEvaluators.h +1688 -0
- data/vendor/eigen/Eigen/src/Core/CoreIterators.h +127 -0
- data/vendor/eigen/Eigen/src/Core/CwiseBinaryOp.h +184 -0
- data/vendor/eigen/Eigen/src/Core/CwiseNullaryOp.h +866 -0
- data/vendor/eigen/Eigen/src/Core/CwiseTernaryOp.h +197 -0
- data/vendor/eigen/Eigen/src/Core/CwiseUnaryOp.h +103 -0
- data/vendor/eigen/Eigen/src/Core/CwiseUnaryView.h +128 -0
- data/vendor/eigen/Eigen/src/Core/DenseBase.h +611 -0
- data/vendor/eigen/Eigen/src/Core/DenseCoeffsBase.h +681 -0
- data/vendor/eigen/Eigen/src/Core/DenseStorage.h +570 -0
- data/vendor/eigen/Eigen/src/Core/Diagonal.h +260 -0
- data/vendor/eigen/Eigen/src/Core/DiagonalMatrix.h +343 -0
- data/vendor/eigen/Eigen/src/Core/DiagonalProduct.h +28 -0
- data/vendor/eigen/Eigen/src/Core/Dot.h +318 -0
- data/vendor/eigen/Eigen/src/Core/EigenBase.h +159 -0
- data/vendor/eigen/Eigen/src/Core/ForceAlignedAccess.h +146 -0
- data/vendor/eigen/Eigen/src/Core/Fuzzy.h +155 -0
- data/vendor/eigen/Eigen/src/Core/GeneralProduct.h +455 -0
- data/vendor/eigen/Eigen/src/Core/GenericPacketMath.h +593 -0
- data/vendor/eigen/Eigen/src/Core/GlobalFunctions.h +187 -0
- data/vendor/eigen/Eigen/src/Core/IO.h +225 -0
- data/vendor/eigen/Eigen/src/Core/Inverse.h +118 -0
- data/vendor/eigen/Eigen/src/Core/Map.h +171 -0
- data/vendor/eigen/Eigen/src/Core/MapBase.h +303 -0
- data/vendor/eigen/Eigen/src/Core/MathFunctions.h +1415 -0
- data/vendor/eigen/Eigen/src/Core/MathFunctionsImpl.h +101 -0
- data/vendor/eigen/Eigen/src/Core/Matrix.h +459 -0
- data/vendor/eigen/Eigen/src/Core/MatrixBase.h +529 -0
- data/vendor/eigen/Eigen/src/Core/NestByValue.h +110 -0
- data/vendor/eigen/Eigen/src/Core/NoAlias.h +108 -0
- data/vendor/eigen/Eigen/src/Core/NumTraits.h +248 -0
- data/vendor/eigen/Eigen/src/Core/PermutationMatrix.h +633 -0
- data/vendor/eigen/Eigen/src/Core/PlainObjectBase.h +1035 -0
- data/vendor/eigen/Eigen/src/Core/Product.h +186 -0
- data/vendor/eigen/Eigen/src/Core/ProductEvaluators.h +1112 -0
- data/vendor/eigen/Eigen/src/Core/Random.h +182 -0
- data/vendor/eigen/Eigen/src/Core/Redux.h +505 -0
- data/vendor/eigen/Eigen/src/Core/Ref.h +283 -0
- data/vendor/eigen/Eigen/src/Core/Replicate.h +142 -0
- data/vendor/eigen/Eigen/src/Core/ReturnByValue.h +117 -0
- data/vendor/eigen/Eigen/src/Core/Reverse.h +211 -0
- data/vendor/eigen/Eigen/src/Core/Select.h +162 -0
- data/vendor/eigen/Eigen/src/Core/SelfAdjointView.h +352 -0
- data/vendor/eigen/Eigen/src/Core/SelfCwiseBinaryOp.h +47 -0
- data/vendor/eigen/Eigen/src/Core/Solve.h +188 -0
- data/vendor/eigen/Eigen/src/Core/SolveTriangular.h +235 -0
- data/vendor/eigen/Eigen/src/Core/SolverBase.h +130 -0
- data/vendor/eigen/Eigen/src/Core/StableNorm.h +221 -0
- data/vendor/eigen/Eigen/src/Core/Stride.h +111 -0
- data/vendor/eigen/Eigen/src/Core/Swap.h +67 -0
- data/vendor/eigen/Eigen/src/Core/Transpose.h +403 -0
- data/vendor/eigen/Eigen/src/Core/Transpositions.h +407 -0
- data/vendor/eigen/Eigen/src/Core/TriangularMatrix.h +983 -0
- data/vendor/eigen/Eigen/src/Core/VectorBlock.h +96 -0
- data/vendor/eigen/Eigen/src/Core/VectorwiseOp.h +695 -0
- data/vendor/eigen/Eigen/src/Core/Visitor.h +273 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/Complex.h +451 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/MathFunctions.h +439 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/PacketMath.h +637 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX/TypeCasting.h +51 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX512/MathFunctions.h +391 -0
- data/vendor/eigen/Eigen/src/Core/arch/AVX512/PacketMath.h +1316 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/Complex.h +430 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/MathFunctions.h +322 -0
- data/vendor/eigen/Eigen/src/Core/arch/AltiVec/PacketMath.h +1061 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/Complex.h +103 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/Half.h +674 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/MathFunctions.h +91 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMath.h +333 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/PacketMathHalf.h +1124 -0
- data/vendor/eigen/Eigen/src/Core/arch/CUDA/TypeCasting.h +212 -0
- data/vendor/eigen/Eigen/src/Core/arch/Default/ConjHelper.h +29 -0
- data/vendor/eigen/Eigen/src/Core/arch/Default/Settings.h +49 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/Complex.h +490 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/MathFunctions.h +91 -0
- data/vendor/eigen/Eigen/src/Core/arch/NEON/PacketMath.h +760 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/Complex.h +471 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/MathFunctions.h +562 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/PacketMath.h +895 -0
- data/vendor/eigen/Eigen/src/Core/arch/SSE/TypeCasting.h +77 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/Complex.h +397 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/MathFunctions.h +137 -0
- data/vendor/eigen/Eigen/src/Core/arch/ZVector/PacketMath.h +945 -0
- data/vendor/eigen/Eigen/src/Core/functors/AssignmentFunctors.h +168 -0
- data/vendor/eigen/Eigen/src/Core/functors/BinaryFunctors.h +475 -0
- data/vendor/eigen/Eigen/src/Core/functors/NullaryFunctors.h +188 -0
- data/vendor/eigen/Eigen/src/Core/functors/StlFunctors.h +136 -0
- data/vendor/eigen/Eigen/src/Core/functors/TernaryFunctors.h +25 -0
- data/vendor/eigen/Eigen/src/Core/functors/UnaryFunctors.h +792 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralBlockPanelKernel.h +2156 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix.h +492 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular.h +311 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h +145 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h +122 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector.h +619 -0
- data/vendor/eigen/Eigen/src/Core/products/GeneralMatrixVector_BLAS.h +136 -0
- data/vendor/eigen/Eigen/src/Core/products/Parallelizer.h +163 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +521 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixMatrix_BLAS.h +287 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector.h +260 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.h +118 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointProduct.h +133 -0
- data/vendor/eigen/Eigen/src/Core/products/SelfadjointRank2Update.h +93 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix.h +466 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixMatrix_BLAS.h +315 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector.h +350 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularMatrixVector_BLAS.h +255 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix.h +335 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverMatrix_BLAS.h +163 -0
- data/vendor/eigen/Eigen/src/Core/products/TriangularSolverVector.h +145 -0
- data/vendor/eigen/Eigen/src/Core/util/BlasUtil.h +398 -0
- data/vendor/eigen/Eigen/src/Core/util/Constants.h +547 -0
- data/vendor/eigen/Eigen/src/Core/util/DisableStupidWarnings.h +83 -0
- data/vendor/eigen/Eigen/src/Core/util/ForwardDeclarations.h +302 -0
- data/vendor/eigen/Eigen/src/Core/util/MKL_support.h +130 -0
- data/vendor/eigen/Eigen/src/Core/util/Macros.h +1001 -0
- data/vendor/eigen/Eigen/src/Core/util/Memory.h +993 -0
- data/vendor/eigen/Eigen/src/Core/util/Meta.h +534 -0
- data/vendor/eigen/Eigen/src/Core/util/NonMPL2.h +3 -0
- data/vendor/eigen/Eigen/src/Core/util/ReenableStupidWarnings.h +27 -0
- data/vendor/eigen/Eigen/src/Core/util/StaticAssert.h +218 -0
- data/vendor/eigen/Eigen/src/Core/util/XprHelper.h +821 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexEigenSolver.h +346 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur.h +459 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/ComplexSchur_LAPACKE.h +91 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/EigenSolver.h +622 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedEigenSolver.h +418 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h +226 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/HessenbergDecomposition.h +374 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/MatrixBaseEigenvalues.h +158 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealQZ.h +654 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur.h +546 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h +77 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +870 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h +87 -0
- data/vendor/eigen/Eigen/src/Eigenvalues/Tridiagonalization.h +556 -0
- data/vendor/eigen/Eigen/src/Geometry/AlignedBox.h +392 -0
- data/vendor/eigen/Eigen/src/Geometry/AngleAxis.h +247 -0
- data/vendor/eigen/Eigen/src/Geometry/EulerAngles.h +114 -0
- data/vendor/eigen/Eigen/src/Geometry/Homogeneous.h +497 -0
- data/vendor/eigen/Eigen/src/Geometry/Hyperplane.h +282 -0
- data/vendor/eigen/Eigen/src/Geometry/OrthoMethods.h +234 -0
- data/vendor/eigen/Eigen/src/Geometry/ParametrizedLine.h +195 -0
- data/vendor/eigen/Eigen/src/Geometry/Quaternion.h +814 -0
- data/vendor/eigen/Eigen/src/Geometry/Rotation2D.h +199 -0
- data/vendor/eigen/Eigen/src/Geometry/RotationBase.h +206 -0
- data/vendor/eigen/Eigen/src/Geometry/Scaling.h +170 -0
- data/vendor/eigen/Eigen/src/Geometry/Transform.h +1542 -0
- data/vendor/eigen/Eigen/src/Geometry/Translation.h +208 -0
- data/vendor/eigen/Eigen/src/Geometry/Umeyama.h +166 -0
- data/vendor/eigen/Eigen/src/Geometry/arch/Geometry_SSE.h +161 -0
- data/vendor/eigen/Eigen/src/Householder/BlockHouseholder.h +103 -0
- data/vendor/eigen/Eigen/src/Householder/Householder.h +172 -0
- data/vendor/eigen/Eigen/src/Householder/HouseholderSequence.h +470 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BasicPreconditioners.h +226 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +228 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +246 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteCholesky.h +400 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +462 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/IterativeSolverBase.h +394 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/LeastSquareConjugateGradient.h +216 -0
- data/vendor/eigen/Eigen/src/IterativeLinearSolvers/SolveWithGuess.h +115 -0
- data/vendor/eigen/Eigen/src/Jacobi/Jacobi.h +462 -0
- data/vendor/eigen/Eigen/src/LU/Determinant.h +101 -0
- data/vendor/eigen/Eigen/src/LU/FullPivLU.h +891 -0
- data/vendor/eigen/Eigen/src/LU/InverseImpl.h +415 -0
- data/vendor/eigen/Eigen/src/LU/PartialPivLU.h +611 -0
- data/vendor/eigen/Eigen/src/LU/PartialPivLU_LAPACKE.h +83 -0
- data/vendor/eigen/Eigen/src/LU/arch/Inverse_SSE.h +338 -0
- data/vendor/eigen/Eigen/src/MetisSupport/MetisSupport.h +137 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Amd.h +445 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Eigen_Colamd.h +1843 -0
- data/vendor/eigen/Eigen/src/OrderingMethods/Ordering.h +157 -0
- data/vendor/eigen/Eigen/src/PaStiXSupport/PaStiXSupport.h +678 -0
- data/vendor/eigen/Eigen/src/PardisoSupport/PardisoSupport.h +543 -0
- data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR.h +653 -0
- data/vendor/eigen/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h +97 -0
- data/vendor/eigen/Eigen/src/QR/CompleteOrthogonalDecomposition.h +562 -0
- data/vendor/eigen/Eigen/src/QR/FullPivHouseholderQR.h +676 -0
- data/vendor/eigen/Eigen/src/QR/HouseholderQR.h +409 -0
- data/vendor/eigen/Eigen/src/QR/HouseholderQR_LAPACKE.h +68 -0
- data/vendor/eigen/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +313 -0
- data/vendor/eigen/Eigen/src/SVD/BDCSVD.h +1246 -0
- data/vendor/eigen/Eigen/src/SVD/JacobiSVD.h +804 -0
- data/vendor/eigen/Eigen/src/SVD/JacobiSVD_LAPACKE.h +91 -0
- data/vendor/eigen/Eigen/src/SVD/SVDBase.h +315 -0
- data/vendor/eigen/Eigen/src/SVD/UpperBidiagonalization.h +414 -0
- data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky.h +689 -0
- data/vendor/eigen/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +199 -0
- data/vendor/eigen/Eigen/src/SparseCore/AmbiVector.h +377 -0
- data/vendor/eigen/Eigen/src/SparseCore/CompressedStorage.h +258 -0
- data/vendor/eigen/Eigen/src/SparseCore/ConservativeSparseSparseProduct.h +352 -0
- data/vendor/eigen/Eigen/src/SparseCore/MappedSparseMatrix.h +67 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseAssign.h +216 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseBlock.h +603 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseColEtree.h +206 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCompressedBase.h +341 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +726 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseCwiseUnaryOp.h +148 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDenseProduct.h +320 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDiagonalProduct.h +138 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseDot.h +98 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseFuzzy.h +29 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMap.h +305 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMatrix.h +1403 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseMatrixBase.h +405 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparsePermutation.h +178 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseProduct.h +169 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseRedux.h +49 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseRef.h +397 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSelfAdjointView.h +656 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSolverBase.h +124 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseSparseProductWithPruning.h +198 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseTranspose.h +92 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseTriangularView.h +189 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseUtil.h +178 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseVector.h +478 -0
- data/vendor/eigen/Eigen/src/SparseCore/SparseView.h +253 -0
- data/vendor/eigen/Eigen/src/SparseCore/TriangularSolver.h +315 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU.h +773 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLUImpl.h +66 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Memory.h +226 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Structs.h +110 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +301 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_Utils.h +80 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_bmod.h +181 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_column_dfs.h +179 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_copy_to_ucol.h +107 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_gemm_kernel.h +280 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_heap_relax_snode.h +126 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_kernel_bmod.h +130 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_bmod.h +223 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_panel_dfs.h +258 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pivotL.h +137 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_pruneL.h +136 -0
- data/vendor/eigen/Eigen/src/SparseLU/SparseLU_relax_snode.h +83 -0
- data/vendor/eigen/Eigen/src/SparseQR/SparseQR.h +745 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdDeque.h +126 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdList.h +106 -0
- data/vendor/eigen/Eigen/src/StlSupport/StdVector.h +131 -0
- data/vendor/eigen/Eigen/src/StlSupport/details.h +84 -0
- data/vendor/eigen/Eigen/src/SuperLUSupport/SuperLUSupport.h +1027 -0
- data/vendor/eigen/Eigen/src/UmfPackSupport/UmfPackSupport.h +506 -0
- data/vendor/eigen/Eigen/src/misc/Image.h +82 -0
- data/vendor/eigen/Eigen/src/misc/Kernel.h +79 -0
- data/vendor/eigen/Eigen/src/misc/RealSvd2x2.h +55 -0
- data/vendor/eigen/Eigen/src/misc/blas.h +440 -0
- data/vendor/eigen/Eigen/src/misc/lapack.h +152 -0
- data/vendor/eigen/Eigen/src/misc/lapacke.h +16291 -0
- data/vendor/eigen/Eigen/src/misc/lapacke_mangling.h +17 -0
- data/vendor/eigen/Eigen/src/plugins/ArrayCwiseBinaryOps.h +332 -0
- data/vendor/eigen/Eigen/src/plugins/ArrayCwiseUnaryOps.h +552 -0
- data/vendor/eigen/Eigen/src/plugins/BlockMethods.h +1058 -0
- data/vendor/eigen/Eigen/src/plugins/CommonCwiseBinaryOps.h +115 -0
- data/vendor/eigen/Eigen/src/plugins/CommonCwiseUnaryOps.h +163 -0
- data/vendor/eigen/Eigen/src/plugins/MatrixCwiseBinaryOps.h +152 -0
- data/vendor/eigen/Eigen/src/plugins/MatrixCwiseUnaryOps.h +85 -0
- data/vendor/eigen/README.md +3 -0
- data/vendor/eigen/bench/README.txt +55 -0
- data/vendor/eigen/bench/btl/COPYING +340 -0
- data/vendor/eigen/bench/btl/README +154 -0
- data/vendor/eigen/bench/tensors/README +21 -0
- data/vendor/eigen/blas/README.txt +6 -0
- data/vendor/eigen/demos/mandelbrot/README +10 -0
- data/vendor/eigen/demos/mix_eigen_and_c/README +9 -0
- data/vendor/eigen/demos/opengl/README +13 -0
- data/vendor/eigen/unsupported/Eigen/CXX11/src/Tensor/README.md +1760 -0
- data/vendor/eigen/unsupported/README.txt +50 -0
- data/vendor/tomotopy/LICENSE +21 -0
- data/vendor/tomotopy/README.kr.rst +375 -0
- data/vendor/tomotopy/README.rst +382 -0
- data/vendor/tomotopy/src/Labeling/FoRelevance.cpp +362 -0
- data/vendor/tomotopy/src/Labeling/FoRelevance.h +88 -0
- data/vendor/tomotopy/src/Labeling/Labeler.h +50 -0
- data/vendor/tomotopy/src/TopicModel/CT.h +37 -0
- data/vendor/tomotopy/src/TopicModel/CTModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/CTModel.hpp +293 -0
- data/vendor/tomotopy/src/TopicModel/DMR.h +51 -0
- data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/DMRModel.hpp +374 -0
- data/vendor/tomotopy/src/TopicModel/DT.h +65 -0
- data/vendor/tomotopy/src/TopicModel/DTM.h +22 -0
- data/vendor/tomotopy/src/TopicModel/DTModel.cpp +15 -0
- data/vendor/tomotopy/src/TopicModel/DTModel.hpp +572 -0
- data/vendor/tomotopy/src/TopicModel/GDMR.h +37 -0
- data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +14 -0
- data/vendor/tomotopy/src/TopicModel/GDMRModel.hpp +485 -0
- data/vendor/tomotopy/src/TopicModel/HDP.h +74 -0
- data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/HDPModel.hpp +592 -0
- data/vendor/tomotopy/src/TopicModel/HLDA.h +40 -0
- data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/HLDAModel.hpp +681 -0
- data/vendor/tomotopy/src/TopicModel/HPA.h +27 -0
- data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +21 -0
- data/vendor/tomotopy/src/TopicModel/HPAModel.hpp +588 -0
- data/vendor/tomotopy/src/TopicModel/LDA.h +144 -0
- data/vendor/tomotopy/src/TopicModel/LDACVB0Model.hpp +442 -0
- data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +1058 -0
- data/vendor/tomotopy/src/TopicModel/LLDA.h +45 -0
- data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/LLDAModel.hpp +203 -0
- data/vendor/tomotopy/src/TopicModel/MGLDA.h +63 -0
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +17 -0
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.hpp +558 -0
- data/vendor/tomotopy/src/TopicModel/PA.h +43 -0
- data/vendor/tomotopy/src/TopicModel/PAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/PAModel.hpp +467 -0
- data/vendor/tomotopy/src/TopicModel/PLDA.h +17 -0
- data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +13 -0
- data/vendor/tomotopy/src/TopicModel/PLDAModel.hpp +214 -0
- data/vendor/tomotopy/src/TopicModel/SLDA.h +54 -0
- data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +17 -0
- data/vendor/tomotopy/src/TopicModel/SLDAModel.hpp +456 -0
- data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +692 -0
- data/vendor/tomotopy/src/Utils/AliasMethod.hpp +169 -0
- data/vendor/tomotopy/src/Utils/Dictionary.h +80 -0
- data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +181 -0
- data/vendor/tomotopy/src/Utils/LBFGS.h +202 -0
- data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBacktracking.h +120 -0
- data/vendor/tomotopy/src/Utils/LBFGS/LineSearchBracketing.h +122 -0
- data/vendor/tomotopy/src/Utils/LBFGS/Param.h +213 -0
- data/vendor/tomotopy/src/Utils/LUT.hpp +82 -0
- data/vendor/tomotopy/src/Utils/MultiNormalDistribution.hpp +69 -0
- data/vendor/tomotopy/src/Utils/PolyaGamma.hpp +200 -0
- data/vendor/tomotopy/src/Utils/PolyaGammaHybrid.hpp +672 -0
- data/vendor/tomotopy/src/Utils/ThreadPool.hpp +150 -0
- data/vendor/tomotopy/src/Utils/Trie.hpp +220 -0
- data/vendor/tomotopy/src/Utils/TruncMultiNormal.hpp +94 -0
- data/vendor/tomotopy/src/Utils/Utils.hpp +337 -0
- data/vendor/tomotopy/src/Utils/avx_gamma.h +46 -0
- data/vendor/tomotopy/src/Utils/avx_mathfun.h +736 -0
- data/vendor/tomotopy/src/Utils/exception.h +28 -0
- data/vendor/tomotopy/src/Utils/math.h +281 -0
- data/vendor/tomotopy/src/Utils/rtnorm.hpp +2690 -0
- data/vendor/tomotopy/src/Utils/sample.hpp +192 -0
- data/vendor/tomotopy/src/Utils/serializer.hpp +695 -0
- data/vendor/tomotopy/src/Utils/slp.hpp +131 -0
- data/vendor/tomotopy/src/Utils/sse_gamma.h +48 -0
- data/vendor/tomotopy/src/Utils/sse_mathfun.h +710 -0
- data/vendor/tomotopy/src/Utils/text.hpp +49 -0
- data/vendor/tomotopy/src/Utils/tvector.hpp +543 -0
- 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
|
+
}
|