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,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Basic.h
|
|
3
|
+
* @author bab2min (bab2min@gmail.com)
|
|
4
|
+
* @brief
|
|
5
|
+
* @version 0.2.0
|
|
6
|
+
* @date 2020-06-22
|
|
7
|
+
*
|
|
8
|
+
* @copyright Copyright (c) 2020
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#ifndef EIGENRAND_DISTS_BASIC_H
|
|
13
|
+
#define EIGENRAND_DISTS_BASIC_H
|
|
14
|
+
|
|
15
|
+
namespace Eigen
|
|
16
|
+
{
|
|
17
|
+
namespace internal
|
|
18
|
+
{
|
|
19
|
+
namespace constant
|
|
20
|
+
{
|
|
21
|
+
static constexpr double pi = 3.1415926535897932;
|
|
22
|
+
static constexpr double e = 2.7182818284590452;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
template<typename Scalar, typename Rng>
|
|
26
|
+
struct scalar_randbits_op : public scalar_base_rng<Scalar, Rng>
|
|
27
|
+
{
|
|
28
|
+
static_assert(std::is_integral<Scalar>::value, "randBits needs integral types.");
|
|
29
|
+
|
|
30
|
+
using scalar_base_rng<Scalar, Rng>::scalar_base_rng;
|
|
31
|
+
|
|
32
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
33
|
+
{
|
|
34
|
+
return pfirst(this->rng());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
template<typename Packet>
|
|
38
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
39
|
+
{
|
|
40
|
+
using RUtils = RawbitsMaker<Packet, Rng>;
|
|
41
|
+
return RUtils{}.rawbits(this->rng);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
template<typename Scalar, typename Urng>
|
|
46
|
+
struct functor_traits<scalar_randbits_op<Scalar, Urng> >
|
|
47
|
+
{
|
|
48
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
template<typename Scalar, typename Rng>
|
|
53
|
+
struct scalar_uniform_real_op : public scalar_base_rng<Scalar, Rng>
|
|
54
|
+
{
|
|
55
|
+
static_assert(std::is_floating_point<Scalar>::value, "uniformReal needs floating point types.");
|
|
56
|
+
|
|
57
|
+
using scalar_base_rng<Scalar, Rng>::scalar_base_rng;
|
|
58
|
+
|
|
59
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
60
|
+
{
|
|
61
|
+
return bit_scalar<Scalar>{}.to_ur(pfirst(this->rng()));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar nzur_scalar() const
|
|
65
|
+
{
|
|
66
|
+
return bit_scalar<Scalar>{}.to_nzur(pfirst(this->rng()));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
template<typename Packet>
|
|
70
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
71
|
+
{
|
|
72
|
+
using RUtils = RandUtils<Packet, Rng>;
|
|
73
|
+
return RUtils{}.uniform_real(this->rng);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
template<typename Scalar, typename Urng>
|
|
78
|
+
struct functor_traits<scalar_uniform_real_op<Scalar, Urng> >
|
|
79
|
+
{
|
|
80
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
template<typename Scalar, typename Rng>
|
|
84
|
+
struct scalar_balanced_op : public scalar_base_rng<Scalar, Rng>
|
|
85
|
+
{
|
|
86
|
+
static_assert(std::is_floating_point<Scalar>::value, "balanced needs floating point types.");
|
|
87
|
+
|
|
88
|
+
using scalar_base_rng<Scalar, Rng>::scalar_base_rng;
|
|
89
|
+
|
|
90
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
91
|
+
{
|
|
92
|
+
return ((Scalar)((int32_t)pfirst(this->rng()) & 0x7FFFFFFF) / 0x7FFFFFFF) * 2 - 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
template<typename Packet>
|
|
96
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
97
|
+
{
|
|
98
|
+
using RUtils = RandUtils<Packet, Rng>;
|
|
99
|
+
return RUtils{}.balanced(this->rng);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
template<typename Scalar, typename Urng>
|
|
104
|
+
struct functor_traits<scalar_balanced_op<Scalar, Urng> >
|
|
105
|
+
{
|
|
106
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#endif
|
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Discrete.h
|
|
3
|
+
* @author bab2min (bab2min@gmail.com)
|
|
4
|
+
* @brief
|
|
5
|
+
* @version 0.2.0
|
|
6
|
+
* @date 2020-06-22
|
|
7
|
+
*
|
|
8
|
+
* @copyright Copyright (c) 2020
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
#ifndef EIGENRAND_DISTS_DISCRETE_H
|
|
13
|
+
#define EIGENRAND_DISTS_DISCRETE_H
|
|
14
|
+
|
|
15
|
+
#include <memory>
|
|
16
|
+
#include <iterator>
|
|
17
|
+
#include <limits>
|
|
18
|
+
|
|
19
|
+
namespace Eigen
|
|
20
|
+
{
|
|
21
|
+
namespace internal
|
|
22
|
+
{
|
|
23
|
+
template<typename Scalar, typename Rng>
|
|
24
|
+
struct scalar_uniform_int_op : public scalar_randbits_op<Scalar, Rng>
|
|
25
|
+
{
|
|
26
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "uniformInt needs integral types.");
|
|
27
|
+
using ur_base = scalar_randbits_op<Scalar, Rng>;
|
|
28
|
+
|
|
29
|
+
Scalar pmin;
|
|
30
|
+
size_t pdiff, bitsize, bitmask;
|
|
31
|
+
|
|
32
|
+
scalar_uniform_int_op(const Rng& _rng, Scalar _min, Scalar _max)
|
|
33
|
+
: ur_base{ _rng }, pmin{ _min }, pdiff{ (size_t)(_max - _min) }
|
|
34
|
+
{
|
|
35
|
+
if ((pdiff + 1) > pdiff)
|
|
36
|
+
{
|
|
37
|
+
bitsize = (size_t)std::ceil(std::log2(pdiff + 1));
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
{
|
|
41
|
+
bitsize = (size_t)std::ceil(std::log2(pdiff));
|
|
42
|
+
}
|
|
43
|
+
bitmask = (Scalar)(((size_t)-1) >> (sizeof(size_t) * 8 - bitsize));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
47
|
+
{
|
|
48
|
+
auto rx = ur_base::operator()();
|
|
49
|
+
if (pdiff == bitmask)
|
|
50
|
+
{
|
|
51
|
+
return (Scalar)(rx & bitmask) + pmin;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
size_t bitcnt = bitsize;
|
|
56
|
+
while (1)
|
|
57
|
+
{
|
|
58
|
+
Scalar cands = (Scalar)(rx & bitmask);
|
|
59
|
+
if (cands <= pdiff) return cands;
|
|
60
|
+
if (bitcnt + bitsize < 32)
|
|
61
|
+
{
|
|
62
|
+
rx >>= bitsize;
|
|
63
|
+
bitcnt += bitsize;
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
{
|
|
67
|
+
rx = ur_base::operator()();
|
|
68
|
+
bitcnt = bitsize;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
template<typename Packet>
|
|
75
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
76
|
+
{
|
|
77
|
+
auto rx = ur_base::template packetOp<Packet>();
|
|
78
|
+
auto pbitmask = pset1<Packet>(bitmask);
|
|
79
|
+
if (pdiff == bitmask)
|
|
80
|
+
{
|
|
81
|
+
return padd(pand(rx, pbitmask), pset1<Packet>(pmin));
|
|
82
|
+
}
|
|
83
|
+
else
|
|
84
|
+
{
|
|
85
|
+
auto& cm = Rand::detail::CompressMask<sizeof(Packet)>::get_inst();
|
|
86
|
+
thread_local Packet cache_rest;
|
|
87
|
+
thread_local int cache_rest_cnt;
|
|
88
|
+
thread_local const scalar_uniform_int_op* cache_ptr = nullptr;
|
|
89
|
+
if (cache_ptr != this)
|
|
90
|
+
{
|
|
91
|
+
cache_ptr = this;
|
|
92
|
+
cache_rest = pset1<Packet>(0);
|
|
93
|
+
cache_rest_cnt = 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
auto plen = pset1<Packet>(pdiff + 1);
|
|
97
|
+
size_t bitcnt = bitsize;
|
|
98
|
+
while (1)
|
|
99
|
+
{
|
|
100
|
+
// accept cands that only < plen
|
|
101
|
+
auto cands = pand(rx, pbitmask);
|
|
102
|
+
bool full = false;
|
|
103
|
+
cache_rest_cnt = cm.compress_append(cands, pcmplt(cands, plen),
|
|
104
|
+
cache_rest, cache_rest_cnt, full);
|
|
105
|
+
if (full) return padd(cands, pset1<Packet>(pmin));
|
|
106
|
+
|
|
107
|
+
if (bitcnt + bitsize < 32)
|
|
108
|
+
{
|
|
109
|
+
rx = psrl(rx, bitsize);
|
|
110
|
+
bitcnt += bitsize;
|
|
111
|
+
}
|
|
112
|
+
else
|
|
113
|
+
{
|
|
114
|
+
rx = ur_base::template packetOp<Packet>();
|
|
115
|
+
bitcnt = bitsize;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
template<typename Scalar, typename Urng>
|
|
123
|
+
struct functor_traits<scalar_uniform_int_op<Scalar, Urng> >
|
|
124
|
+
{
|
|
125
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
template<typename _Precision = uint32_t, typename _Size = uint32_t>
|
|
129
|
+
class AliasMethod
|
|
130
|
+
{
|
|
131
|
+
std::unique_ptr<_Precision[]> arr;
|
|
132
|
+
std::unique_ptr<_Size[]> alias;
|
|
133
|
+
size_t msize = 0, bitsize = 0, bitmask = 0;
|
|
134
|
+
|
|
135
|
+
public:
|
|
136
|
+
AliasMethod()
|
|
137
|
+
{
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
AliasMethod(const AliasMethod& o)
|
|
141
|
+
{
|
|
142
|
+
operator=(o);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
AliasMethod(AliasMethod&& o)
|
|
146
|
+
{
|
|
147
|
+
operator=(o);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
AliasMethod& operator=(const AliasMethod& o)
|
|
151
|
+
{
|
|
152
|
+
msize = o.msize;
|
|
153
|
+
bitsize = o.bitsize;
|
|
154
|
+
bitmask = o.bitmask;
|
|
155
|
+
if (msize)
|
|
156
|
+
{
|
|
157
|
+
arr = std::unique_ptr<_Precision[]>(new _Precision[1 << bitsize]);
|
|
158
|
+
alias = std::unique_ptr<_Size[]>(new _Size[1 << bitsize]);
|
|
159
|
+
|
|
160
|
+
std::copy(o.arr.get(), o.arr.get() + (1 << bitsize), arr.get());
|
|
161
|
+
std::copy(o.alias.get(), o.alias.get() + (1 << bitsize), alias.get());
|
|
162
|
+
}
|
|
163
|
+
return *this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
AliasMethod& operator=(AliasMethod&& o)
|
|
167
|
+
{
|
|
168
|
+
msize = o.msize;
|
|
169
|
+
bitsize = o.bitsize;
|
|
170
|
+
bitmask = o.bitmask;
|
|
171
|
+
std::swap(arr, o.arr);
|
|
172
|
+
std::swap(alias, o.alias);
|
|
173
|
+
return *this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
template<typename _Iter>
|
|
177
|
+
AliasMethod(_Iter first, _Iter last)
|
|
178
|
+
{
|
|
179
|
+
buildTable(first, last);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
template<typename _Iter>
|
|
183
|
+
void buildTable(_Iter first, _Iter last)
|
|
184
|
+
{
|
|
185
|
+
size_t psize, nbsize;
|
|
186
|
+
msize = 0;
|
|
187
|
+
double sum = 0;
|
|
188
|
+
for (auto it = first; it != last; ++it, ++msize)
|
|
189
|
+
{
|
|
190
|
+
sum += *it;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (!std::isfinite(sum)) throw std::invalid_argument{ "cannot build NaN value distribution" };
|
|
194
|
+
|
|
195
|
+
// ceil to power of 2
|
|
196
|
+
nbsize = (size_t)std::ceil(std::log2(msize));
|
|
197
|
+
psize = (size_t)1 << nbsize;
|
|
198
|
+
|
|
199
|
+
if (nbsize != bitsize)
|
|
200
|
+
{
|
|
201
|
+
arr = std::unique_ptr<_Precision[]>(new _Precision[psize]);
|
|
202
|
+
std::fill(arr.get(), arr.get() + psize, 0);
|
|
203
|
+
alias = std::unique_ptr<_Size[]>(new _Size[psize]);
|
|
204
|
+
bitsize = nbsize;
|
|
205
|
+
bitmask = ((size_t)(-1)) >> (sizeof(size_t) * 8 - bitsize);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
sum /= psize;
|
|
209
|
+
|
|
210
|
+
auto f = std::unique_ptr<double[]>(new double[psize]);
|
|
211
|
+
auto pf = f.get();
|
|
212
|
+
for (auto it = first; it != last; ++it, ++pf)
|
|
213
|
+
{
|
|
214
|
+
*pf = *it / sum;
|
|
215
|
+
}
|
|
216
|
+
std::fill(pf, pf + psize - msize, 0);
|
|
217
|
+
|
|
218
|
+
size_t over = 0, under = 0, mm;
|
|
219
|
+
while (over < psize && f[over] < 1) ++over;
|
|
220
|
+
while (under < psize && f[under] >= 1) ++under;
|
|
221
|
+
mm = under + 1;
|
|
222
|
+
|
|
223
|
+
while (over < psize && under < psize)
|
|
224
|
+
{
|
|
225
|
+
if (std::is_integral<_Precision>::value)
|
|
226
|
+
{
|
|
227
|
+
arr[under] = (_Precision)(f[under] * (std::numeric_limits<_Precision>::max() + 1.0));
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
{
|
|
231
|
+
arr[under] = (_Precision)f[under];
|
|
232
|
+
}
|
|
233
|
+
alias[under] = over;
|
|
234
|
+
f[over] += f[under] - 1;
|
|
235
|
+
if (f[over] >= 1 || mm <= over)
|
|
236
|
+
{
|
|
237
|
+
for (under = mm; under < psize && f[under] >= 1; ++under);
|
|
238
|
+
mm = under + 1;
|
|
239
|
+
}
|
|
240
|
+
else
|
|
241
|
+
{
|
|
242
|
+
under = over;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
while (over < psize && f[over] < 1) ++over;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
for (; over < psize; ++over)
|
|
249
|
+
{
|
|
250
|
+
if (f[over] >= 1)
|
|
251
|
+
{
|
|
252
|
+
if (std::is_integral<_Precision>::value)
|
|
253
|
+
{
|
|
254
|
+
arr[over] = std::numeric_limits<_Precision>::max();
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
{
|
|
258
|
+
arr[over] = 1;
|
|
259
|
+
}
|
|
260
|
+
alias[over] = over;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (under < psize)
|
|
265
|
+
{
|
|
266
|
+
if (std::is_integral<_Precision>::value)
|
|
267
|
+
{
|
|
268
|
+
arr[under] = std::numeric_limits<_Precision>::max();
|
|
269
|
+
}
|
|
270
|
+
else
|
|
271
|
+
{
|
|
272
|
+
arr[under] = 1;
|
|
273
|
+
}
|
|
274
|
+
alias[under] = under;
|
|
275
|
+
for (under = mm; under < msize; ++under)
|
|
276
|
+
{
|
|
277
|
+
if (f[under] < 1)
|
|
278
|
+
{
|
|
279
|
+
if (std::is_integral<_Precision>::value)
|
|
280
|
+
{
|
|
281
|
+
arr[under] = std::numeric_limits<_Precision>::max();
|
|
282
|
+
}
|
|
283
|
+
else
|
|
284
|
+
{
|
|
285
|
+
arr[under] = 1;
|
|
286
|
+
}
|
|
287
|
+
alias[under] = under;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
size_t get_bitsize() const
|
|
294
|
+
{
|
|
295
|
+
return bitsize;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
size_t get_bitmask() const
|
|
299
|
+
{
|
|
300
|
+
return bitmask;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const _Precision* get_prob() const
|
|
304
|
+
{
|
|
305
|
+
return arr.get();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const _Size* get_alias() const
|
|
309
|
+
{
|
|
310
|
+
return alias.get();
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
template<typename Scalar, typename Rng, typename Precision = float>
|
|
315
|
+
struct scalar_discrete_dist_op;
|
|
316
|
+
|
|
317
|
+
template<typename Scalar, typename Rng>
|
|
318
|
+
struct scalar_discrete_dist_op<Scalar, Rng, int32_t> : public scalar_randbits_op<Scalar, Rng>
|
|
319
|
+
{
|
|
320
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "discreteDist needs integral types.");
|
|
321
|
+
using ur_base = scalar_randbits_op<Scalar, Rng>;
|
|
322
|
+
|
|
323
|
+
std::vector<uint32_t> cdf;
|
|
324
|
+
AliasMethod<int32_t, Scalar> alias_table;
|
|
325
|
+
|
|
326
|
+
template<typename RealIter>
|
|
327
|
+
scalar_discrete_dist_op(const Rng& _rng, RealIter first, RealIter last)
|
|
328
|
+
: ur_base{ _rng }
|
|
329
|
+
{
|
|
330
|
+
if (std::distance(first, last) < 16)
|
|
331
|
+
{
|
|
332
|
+
// use linear or binary search
|
|
333
|
+
std::vector<double> _cdf;
|
|
334
|
+
double acc = 0;
|
|
335
|
+
for (; first != last; ++first)
|
|
336
|
+
{
|
|
337
|
+
_cdf.emplace_back(acc += *first);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
for (auto& p : _cdf)
|
|
341
|
+
{
|
|
342
|
+
cdf.emplace_back((uint32_t)(p / _cdf.back() * 0x80000000));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
{
|
|
347
|
+
// use alias table
|
|
348
|
+
alias_table = AliasMethod<int32_t, Scalar>{ first, last };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
353
|
+
{
|
|
354
|
+
if (!cdf.empty())
|
|
355
|
+
{
|
|
356
|
+
auto rx = ur_base::operator()() & 0x7FFFFFFF;
|
|
357
|
+
return (Scalar)(std::lower_bound(cdf.begin(), cdf.end() - 1, rx) - cdf.begin());
|
|
358
|
+
}
|
|
359
|
+
else
|
|
360
|
+
{
|
|
361
|
+
auto rx = ur_base::operator()();
|
|
362
|
+
auto albit = rx & alias_table.get_bitmask();
|
|
363
|
+
uint32_t alx = (uint32_t)(rx >> (sizeof(rx) * 8 - 31));
|
|
364
|
+
if (alx < alias_table.get_prob()[albit]) return albit;
|
|
365
|
+
return alias_table.get_alias()[albit];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
template<typename Packet>
|
|
370
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
371
|
+
{
|
|
372
|
+
#ifdef EIGEN_VECTORIZE_AVX2
|
|
373
|
+
thread_local Packet4i cache;
|
|
374
|
+
thread_local const scalar_discrete_dist_op* cache_ptr = nullptr;
|
|
375
|
+
if (cache_ptr == this)
|
|
376
|
+
{
|
|
377
|
+
cache_ptr = nullptr;
|
|
378
|
+
return cache;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
using PacketType = Packet8i;
|
|
382
|
+
#else
|
|
383
|
+
using PacketType = Packet;
|
|
384
|
+
#endif
|
|
385
|
+
|
|
386
|
+
PacketType ret;
|
|
387
|
+
if (!cdf.empty())
|
|
388
|
+
{
|
|
389
|
+
ret = pset1<PacketType>(cdf.size() - 1);
|
|
390
|
+
auto rx = pand(ur_base::template packetOp<PacketType>(), pset1<PacketType>(0x7FFFFFFF));
|
|
391
|
+
for (size_t i = 0; i < cdf.size() - 1; ++i)
|
|
392
|
+
{
|
|
393
|
+
ret = padd(ret, pcmplt(rx, pset1<PacketType>(cdf[i])));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else
|
|
397
|
+
{
|
|
398
|
+
auto rx = ur_base::template packetOp<PacketType>();
|
|
399
|
+
auto albit = pand(rx, pset1<PacketType>(alias_table.get_bitmask()));
|
|
400
|
+
auto c = pcmplt(psrl(rx, 1), pgather(alias_table.get_prob(), albit));
|
|
401
|
+
ret = pblendv(c, albit, pgather(alias_table.get_alias(), albit));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
#ifdef EIGEN_VECTORIZE_AVX2
|
|
405
|
+
cache = _mm256_extractf128_si256(ret, 1);
|
|
406
|
+
cache_ptr = this;
|
|
407
|
+
return _mm256_extractf128_si256(ret, 0);
|
|
408
|
+
#else
|
|
409
|
+
return ret;
|
|
410
|
+
#endif
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
template<typename Scalar, typename Rng>
|
|
415
|
+
struct scalar_discrete_dist_op<Scalar, Rng, float> : public scalar_uniform_real_op<float, Rng>
|
|
416
|
+
{
|
|
417
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "discreteDist needs integral types.");
|
|
418
|
+
using ur_base = scalar_uniform_real_op<float, Rng>;
|
|
419
|
+
|
|
420
|
+
std::vector<float> cdf;
|
|
421
|
+
AliasMethod<float, Scalar> alias_table;
|
|
422
|
+
|
|
423
|
+
template<typename RealIter>
|
|
424
|
+
scalar_discrete_dist_op(const Rng& _rng, RealIter first, RealIter last)
|
|
425
|
+
: ur_base{ _rng }
|
|
426
|
+
{
|
|
427
|
+
if (std::distance(first, last) < 16)
|
|
428
|
+
{
|
|
429
|
+
// use linear or binary search
|
|
430
|
+
std::vector<double> _cdf;
|
|
431
|
+
double acc = 0;
|
|
432
|
+
for (; first != last; ++first)
|
|
433
|
+
{
|
|
434
|
+
_cdf.emplace_back(acc += *first);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
for (auto& p : _cdf)
|
|
438
|
+
{
|
|
439
|
+
cdf.emplace_back(p / _cdf.back());
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
else
|
|
443
|
+
{
|
|
444
|
+
// use alias table
|
|
445
|
+
alias_table = AliasMethod<float, Scalar>{ first, last };
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
450
|
+
{
|
|
451
|
+
if (!cdf.empty())
|
|
452
|
+
{
|
|
453
|
+
auto rx = ur_base::operator()();
|
|
454
|
+
return (Scalar)(std::lower_bound(cdf.begin(), cdf.end() - 1, rx) - cdf.begin());
|
|
455
|
+
}
|
|
456
|
+
else
|
|
457
|
+
{
|
|
458
|
+
auto albit = pfirst(this->rng()) & alias_table.get_bitmask();
|
|
459
|
+
auto alx = ur_base::operator()();
|
|
460
|
+
if (alx < alias_table.get_prob()[albit]) return albit;
|
|
461
|
+
return alias_table.get_alias()[albit];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
template<typename Packet>
|
|
466
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
467
|
+
{
|
|
468
|
+
using PacketType = decltype(reinterpret_to_float(std::declval<Packet>()));
|
|
469
|
+
|
|
470
|
+
if (!cdf.empty())
|
|
471
|
+
{
|
|
472
|
+
auto ret = pset1<Packet>(cdf.size());
|
|
473
|
+
auto rx = ur_base::template packetOp<PacketType>();
|
|
474
|
+
for (auto& p : cdf)
|
|
475
|
+
{
|
|
476
|
+
ret = padd(ret, reinterpret_to_int(pcmplt(rx, pset1<PacketType>(p))));
|
|
477
|
+
}
|
|
478
|
+
return ret;
|
|
479
|
+
}
|
|
480
|
+
else
|
|
481
|
+
{
|
|
482
|
+
using RUtils = RawbitsMaker<Packet, Rng>;
|
|
483
|
+
auto albit = pand(RUtils{}.rawbits(this->rng), pset1<Packet>(alias_table.get_bitmask()));
|
|
484
|
+
auto c = reinterpret_to_int(pcmplt(ur_base::template packetOp<PacketType>(), pgather(alias_table.get_prob(), albit)));
|
|
485
|
+
return pblendv(c, albit, pgather(alias_table.get_alias(), albit));
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
template<typename Scalar, typename Rng>
|
|
491
|
+
struct scalar_discrete_dist_op<Scalar, Rng, double> : public scalar_uniform_real_op<double, Rng>
|
|
492
|
+
{
|
|
493
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "discreteDist needs integral types.");
|
|
494
|
+
using ur_base = scalar_uniform_real_op<double, Rng>;
|
|
495
|
+
|
|
496
|
+
std::vector<double> cdf;
|
|
497
|
+
AliasMethod<double, Scalar> alias_table;
|
|
498
|
+
|
|
499
|
+
template<typename RealIter>
|
|
500
|
+
scalar_discrete_dist_op(const Rng& _rng, RealIter first, RealIter last)
|
|
501
|
+
: ur_base{ _rng }
|
|
502
|
+
{
|
|
503
|
+
if (std::distance(first, last) < 16)
|
|
504
|
+
{
|
|
505
|
+
// use linear or binary search
|
|
506
|
+
std::vector<double> _cdf;
|
|
507
|
+
double acc = 0;
|
|
508
|
+
for (; first != last; ++first)
|
|
509
|
+
{
|
|
510
|
+
_cdf.emplace_back(acc += *first);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
for (auto& p : _cdf)
|
|
514
|
+
{
|
|
515
|
+
cdf.emplace_back(p / _cdf.back());
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
else
|
|
519
|
+
{
|
|
520
|
+
// use alias table
|
|
521
|
+
alias_table = AliasMethod<double, Scalar>{ first, last };
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
526
|
+
{
|
|
527
|
+
if (!cdf.empty())
|
|
528
|
+
{
|
|
529
|
+
auto rx = ur_base::operator()();
|
|
530
|
+
return (Scalar)(std::lower_bound(cdf.begin(), cdf.end() - 1, rx) - cdf.begin());
|
|
531
|
+
}
|
|
532
|
+
else
|
|
533
|
+
{
|
|
534
|
+
auto albit = pfirst(this->rng()) & alias_table.get_bitmask();
|
|
535
|
+
auto alx = ur_base::operator()();
|
|
536
|
+
if (alx < alias_table.get_prob()[albit]) return albit;
|
|
537
|
+
return alias_table.get_alias()[albit];
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
template<typename Packet>
|
|
542
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
543
|
+
{
|
|
544
|
+
using DPacket = decltype(reinterpret_to_double(std::declval<Packet>()));
|
|
545
|
+
if (!cdf.empty())
|
|
546
|
+
{
|
|
547
|
+
auto ret = pset1<Packet>(cdf.size());
|
|
548
|
+
#ifdef EIGEN_VECTORIZE_AVX
|
|
549
|
+
auto rx = ur_base::template packetOp<Packet4d>();
|
|
550
|
+
for (auto& p : cdf)
|
|
551
|
+
{
|
|
552
|
+
auto c = reinterpret_to_int(pcmplt(rx, pset1<decltype(rx)>(p)));
|
|
553
|
+
auto r = combine_low32(c);
|
|
554
|
+
ret = padd(ret, r);
|
|
555
|
+
}
|
|
556
|
+
#else
|
|
557
|
+
auto rx1 = ur_base::template packetOp<DPacket>(),
|
|
558
|
+
rx2 = ur_base::template packetOp<DPacket>();
|
|
559
|
+
for (auto& p : cdf)
|
|
560
|
+
{
|
|
561
|
+
auto pp = pset1<decltype(rx1)>(p);
|
|
562
|
+
ret = padd(ret, combine_low32(reinterpret_to_int(pcmplt(rx1, pp)), reinterpret_to_int(pcmplt(rx2, pp))));
|
|
563
|
+
}
|
|
564
|
+
#endif
|
|
565
|
+
return ret;
|
|
566
|
+
}
|
|
567
|
+
else
|
|
568
|
+
{
|
|
569
|
+
#ifdef EIGEN_VECTORIZE_AVX
|
|
570
|
+
using RUtils = RawbitsMaker<Packet, Rng>;
|
|
571
|
+
auto albit = pand(RUtils{}.rawbits(this->rng), pset1<Packet>(alias_table.get_bitmask()));
|
|
572
|
+
auto c = reinterpret_to_int(pcmplt(ur_base::template packetOp<Packet4d>(), pgather(alias_table.get_prob(), _mm256_castsi128_si256(albit))));
|
|
573
|
+
return pblendv(combine_low32(c), albit, pgather(alias_table.get_alias(), albit));
|
|
574
|
+
#else
|
|
575
|
+
using RUtils = RawbitsMaker<Packet, Rng>;
|
|
576
|
+
auto albit = pand(RUtils{}.rawbits(this->rng), pset1<Packet>(alias_table.get_bitmask()));
|
|
577
|
+
auto c1 = reinterpret_to_int(pcmplt(ur_base::template packetOp<DPacket>(), pgather(alias_table.get_prob(), albit)));
|
|
578
|
+
auto c2 = reinterpret_to_int(pcmplt(ur_base::template packetOp<DPacket>(), pgather(alias_table.get_prob(), albit, true)));
|
|
579
|
+
return pblendv(combine_low32(c1, c2), albit, pgather(alias_table.get_alias(), albit));
|
|
580
|
+
#endif
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
template<typename Scalar, typename Urng, typename Precision>
|
|
586
|
+
struct functor_traits<scalar_discrete_dist_op<Scalar, Urng, Precision> >
|
|
587
|
+
{
|
|
588
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
template<typename Scalar, typename Rng>
|
|
592
|
+
struct scalar_poisson_dist_op : public scalar_uniform_real_op<float, Rng>
|
|
593
|
+
{
|
|
594
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "poisson needs integral types.");
|
|
595
|
+
using ur_base = scalar_uniform_real_op<float, Rng>;
|
|
596
|
+
|
|
597
|
+
double mean, ne_mean, sqrt_tmean, log_mean, g1;
|
|
598
|
+
|
|
599
|
+
scalar_poisson_dist_op(const Rng& _rng, double _mean)
|
|
600
|
+
: ur_base{ _rng }, mean{ _mean }, ne_mean{ std::exp(-_mean) }
|
|
601
|
+
{
|
|
602
|
+
sqrt_tmean = std::sqrt(2 * mean);
|
|
603
|
+
log_mean = std::log(mean);
|
|
604
|
+
g1 = mean * log_mean - std::lgamma(mean + 1);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
608
|
+
{
|
|
609
|
+
if (mean < 12)
|
|
610
|
+
{
|
|
611
|
+
Scalar res = 0;
|
|
612
|
+
double val = 1;
|
|
613
|
+
for (; ; ++res)
|
|
614
|
+
{
|
|
615
|
+
val *= ur_base::operator()();
|
|
616
|
+
if (val <= ne_mean) break;
|
|
617
|
+
}
|
|
618
|
+
return res;
|
|
619
|
+
}
|
|
620
|
+
else
|
|
621
|
+
{
|
|
622
|
+
Scalar res;
|
|
623
|
+
double yx;
|
|
624
|
+
while(1)
|
|
625
|
+
{
|
|
626
|
+
yx = std::tan(constant::pi * ur_base::operator()());
|
|
627
|
+
res = (Scalar)(sqrt_tmean * yx + mean);
|
|
628
|
+
if (res >= 0 && ur_base::operator()() <= 0.9 * (1.0 + yx * yx)
|
|
629
|
+
* std::exp(res * log_mean - std::lgamma(res + 1.0) - g1))
|
|
630
|
+
{
|
|
631
|
+
return res;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
template<typename Packet>
|
|
638
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
639
|
+
{
|
|
640
|
+
using PacketType = decltype(reinterpret_to_float(std::declval<Packet>()));
|
|
641
|
+
|
|
642
|
+
if (mean < 12)
|
|
643
|
+
{
|
|
644
|
+
Packet res = pset1<Packet>(0);
|
|
645
|
+
PacketType val = pset1<PacketType>(1), pne_mean = pset1<PacketType>(ne_mean);
|
|
646
|
+
while (1)
|
|
647
|
+
{
|
|
648
|
+
val = pmul(val, ur_base::template packetOp<PacketType>());
|
|
649
|
+
auto c = reinterpret_to_int(pcmplt(pne_mean, val));
|
|
650
|
+
if (pmovemask(c) == 0) break;
|
|
651
|
+
res = padd(res, pnegate(c));
|
|
652
|
+
}
|
|
653
|
+
return res;
|
|
654
|
+
}
|
|
655
|
+
else
|
|
656
|
+
{
|
|
657
|
+
auto& cm = Rand::detail::CompressMask<sizeof(Packet)>::get_inst();
|
|
658
|
+
thread_local PacketType cache_rest;
|
|
659
|
+
thread_local int cache_rest_cnt;
|
|
660
|
+
thread_local const scalar_poisson_dist_op* cache_ptr = nullptr;
|
|
661
|
+
if (cache_ptr != this)
|
|
662
|
+
{
|
|
663
|
+
cache_ptr = this;
|
|
664
|
+
cache_rest = pset1<PacketType>(0);
|
|
665
|
+
cache_rest_cnt = 0;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const PacketType ppi = pset1<PacketType>(constant::pi),
|
|
669
|
+
psqrt_tmean = pset1<PacketType>(sqrt_tmean),
|
|
670
|
+
pmean = pset1<PacketType>(mean),
|
|
671
|
+
plog_mean = pset1<PacketType>(log_mean),
|
|
672
|
+
pg1 = pset1<PacketType>(g1);
|
|
673
|
+
while (1)
|
|
674
|
+
{
|
|
675
|
+
PacketType fres, yx, psin, pcos;
|
|
676
|
+
psincos(pmul(ppi, ur_base::template packetOp<PacketType>()), psin, pcos);
|
|
677
|
+
yx = pdiv(psin, pcos);
|
|
678
|
+
fres = ptruncate(padd(pmul(psqrt_tmean, yx), pmean));
|
|
679
|
+
|
|
680
|
+
auto p1 = pmul(padd(pmul(yx, yx), pset1<PacketType>(1)), pset1<PacketType>(0.9));
|
|
681
|
+
auto p2 = pexp(psub(psub(pmul(fres, plog_mean), plgamma(padd(fres, pset1<PacketType>(1)))), pg1));
|
|
682
|
+
|
|
683
|
+
auto c1 = pcmple(pset1<PacketType>(0), fres);
|
|
684
|
+
auto c2 = pcmple(ur_base::template packetOp<PacketType>(), pmul(p1, p2));
|
|
685
|
+
|
|
686
|
+
auto cands = fres;
|
|
687
|
+
bool full = false;
|
|
688
|
+
cache_rest_cnt = cm.compress_append(cands, pand(c1, c2),
|
|
689
|
+
cache_rest, cache_rest_cnt, full);
|
|
690
|
+
if (full) return pcast<PacketType, Packet>(cands);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
template<typename Scalar, typename Urng>
|
|
697
|
+
struct functor_traits<scalar_poisson_dist_op<Scalar, Urng> >
|
|
698
|
+
{
|
|
699
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
template<typename Scalar, typename Rng>
|
|
703
|
+
struct scalar_binomial_dist_op : public scalar_poisson_dist_op<Scalar, Rng>
|
|
704
|
+
{
|
|
705
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "binomial needs integral types.");
|
|
706
|
+
using ur_base = scalar_uniform_real_op<float, Rng>;
|
|
707
|
+
|
|
708
|
+
Scalar trials;
|
|
709
|
+
double p, small_p, g1, sqrt_v, log_small_p, log_small_q;
|
|
710
|
+
|
|
711
|
+
scalar_binomial_dist_op(const Rng& _rng, Scalar _trials = 1, double _p = 0.5)
|
|
712
|
+
: scalar_poisson_dist_op<Scalar, Rng>{ _rng, _trials * std::min(_p, 1 - _p) },
|
|
713
|
+
trials{ _trials }, p{ _p }, small_p{ std::min(p, 1 - p) }
|
|
714
|
+
|
|
715
|
+
{
|
|
716
|
+
g1 = std::lgamma(trials + 1);
|
|
717
|
+
sqrt_v = std::sqrt(2 * this->mean * (1 - small_p));
|
|
718
|
+
log_small_p = std::log(small_p);
|
|
719
|
+
log_small_q = std::log(1 - small_p);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
723
|
+
{
|
|
724
|
+
Scalar res;
|
|
725
|
+
if (trials < 25)
|
|
726
|
+
{
|
|
727
|
+
res = 0;
|
|
728
|
+
for (int i = 0; i < trials; ++i)
|
|
729
|
+
{
|
|
730
|
+
if (ur_base::operator()() < p) ++res;
|
|
731
|
+
}
|
|
732
|
+
return res;
|
|
733
|
+
}
|
|
734
|
+
else if (this->mean < 1.0)
|
|
735
|
+
{
|
|
736
|
+
res = scalar_poisson_dist_op<Scalar, Rng>::operator()();
|
|
737
|
+
}
|
|
738
|
+
else
|
|
739
|
+
{
|
|
740
|
+
while(1)
|
|
741
|
+
{
|
|
742
|
+
double ys;
|
|
743
|
+
ys = std::tan(constant::pi * ur_base::operator()());
|
|
744
|
+
res = (Scalar)(sqrt_v * ys + this->mean);
|
|
745
|
+
if (0 <= res && res <= trials && ur_base::operator()() <= 1.2 * sqrt_v
|
|
746
|
+
* (1.0 + ys * ys)
|
|
747
|
+
* std::exp(g1 - std::lgamma(res + 1)
|
|
748
|
+
- std::lgamma(trials - res + 1.0)
|
|
749
|
+
+ res * log_small_p
|
|
750
|
+
+ (trials - res) * log_small_q)
|
|
751
|
+
)
|
|
752
|
+
{
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return p == small_p ? res : trials - res;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
template<typename Packet>
|
|
761
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
762
|
+
{
|
|
763
|
+
using PacketType = decltype(reinterpret_to_float(std::declval<Packet>()));
|
|
764
|
+
Packet res;
|
|
765
|
+
if (trials < 25)
|
|
766
|
+
{
|
|
767
|
+
PacketType pp = pset1<PacketType>(p);
|
|
768
|
+
res = pset1<Packet>(trials);
|
|
769
|
+
for (int i = 0; i < trials; ++i)
|
|
770
|
+
{
|
|
771
|
+
auto c = reinterpret_to_int(pcmple(pp, ur_base::template packetOp<PacketType>()));
|
|
772
|
+
res = padd(res, c);
|
|
773
|
+
}
|
|
774
|
+
return res;
|
|
775
|
+
}
|
|
776
|
+
else if (this->mean < 1.0)
|
|
777
|
+
{
|
|
778
|
+
res = scalar_poisson_dist_op<Scalar, Rng>::template packetOp<Packet>();
|
|
779
|
+
}
|
|
780
|
+
else
|
|
781
|
+
{
|
|
782
|
+
auto& cm = Rand::detail::CompressMask<sizeof(Packet)>::get_inst();
|
|
783
|
+
thread_local PacketType cache_rest;
|
|
784
|
+
thread_local int cache_rest_cnt;
|
|
785
|
+
thread_local const scalar_binomial_dist_op* cache_ptr = nullptr;
|
|
786
|
+
if (cache_ptr != this)
|
|
787
|
+
{
|
|
788
|
+
cache_ptr = this;
|
|
789
|
+
cache_rest = pset1<PacketType>(0);
|
|
790
|
+
cache_rest_cnt = 0;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const PacketType ppi = pset1<PacketType>(constant::pi),
|
|
794
|
+
ptrials = pset1<PacketType>(trials),
|
|
795
|
+
psqrt_v = pset1<PacketType>(sqrt_v),
|
|
796
|
+
pmean = pset1<PacketType>(this->mean),
|
|
797
|
+
plog_small_p = pset1<PacketType>(log_small_p),
|
|
798
|
+
plog_small_q = pset1<PacketType>(log_small_q),
|
|
799
|
+
pg1 = pset1<PacketType>(g1);
|
|
800
|
+
while (1)
|
|
801
|
+
{
|
|
802
|
+
PacketType fres, ys, psin, pcos;
|
|
803
|
+
psincos(pmul(ppi, ur_base::template packetOp<PacketType>()), psin, pcos);
|
|
804
|
+
ys = pdiv(psin, pcos);
|
|
805
|
+
fres = ptruncate(padd(pmul(psqrt_v, ys), pmean));
|
|
806
|
+
|
|
807
|
+
auto p1 = pmul(pmul(pset1<PacketType>(1.2), psqrt_v), padd(pset1<PacketType>(1), pmul(ys, ys)));
|
|
808
|
+
auto p2 = pexp(
|
|
809
|
+
padd(padd(psub(
|
|
810
|
+
psub(pg1, plgamma(padd(fres, pset1<PacketType>(1)))),
|
|
811
|
+
plgamma(psub(padd(ptrials, pset1<PacketType>(1)), fres))
|
|
812
|
+
), pmul(fres, plog_small_p)), pmul(psub(ptrials, fres), plog_small_q))
|
|
813
|
+
);
|
|
814
|
+
|
|
815
|
+
auto c1 = pand(pcmple(pset1<PacketType>(0), fres), pcmple(fres, ptrials));
|
|
816
|
+
auto c2 = pcmple(ur_base::template packetOp<PacketType>(), pmul(p1, p2));
|
|
817
|
+
|
|
818
|
+
auto cands = fres;
|
|
819
|
+
bool full = false;
|
|
820
|
+
cache_rest_cnt = cm.compress_append(cands, pand(c1, c2),
|
|
821
|
+
cache_rest, cache_rest_cnt, full);
|
|
822
|
+
if (full)
|
|
823
|
+
{
|
|
824
|
+
res = pcast<PacketType, Packet>(cands);
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
return p == small_p ? res : psub(pset1<Packet>(trials), res);
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
template<typename Scalar, typename Urng>
|
|
834
|
+
struct functor_traits<scalar_binomial_dist_op<Scalar, Urng> >
|
|
835
|
+
{
|
|
836
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
template<typename Scalar, typename Rng>
|
|
840
|
+
struct scalar_geometric_dist_op : public scalar_uniform_real_op<float, Rng>
|
|
841
|
+
{
|
|
842
|
+
static_assert(std::is_same<Scalar, int32_t>::value, "geomtric needs integral types.");
|
|
843
|
+
using ur_base = scalar_uniform_real_op<float, Rng>;
|
|
844
|
+
|
|
845
|
+
double p, rlog_q;
|
|
846
|
+
|
|
847
|
+
scalar_geometric_dist_op(const Rng& _rng, double _p)
|
|
848
|
+
: ur_base{ _rng }, p{ _p }, rlog_q{ 1 / std::log(1 - p) }
|
|
849
|
+
{
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() () const
|
|
853
|
+
{
|
|
854
|
+
return (Scalar)(std::log(1 - ur_base::operator()()) * rlog_q);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
template<typename Packet>
|
|
858
|
+
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Packet packetOp() const
|
|
859
|
+
{
|
|
860
|
+
using PacketType = decltype(reinterpret_to_float(std::declval<Packet>()));
|
|
861
|
+
|
|
862
|
+
return pcast<PacketType, Packet>(ptruncate(pmul(plog(
|
|
863
|
+
psub(pset1<PacketType>(1), ur_base::template packetOp<PacketType>())
|
|
864
|
+
), pset1<PacketType>(rlog_q))));
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
template<typename Scalar, typename Urng>
|
|
869
|
+
struct functor_traits<scalar_geometric_dist_op<Scalar, Urng> >
|
|
870
|
+
{
|
|
871
|
+
enum { Cost = HugeCost, PacketAccess = packet_traits<Scalar>::Vectorizable, IsRepeatable = false };
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
#endif
|