├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── examples ├── README.md ├── results │ ├── supervised │ │ ├── supervised_example_1k_Phat.txt │ │ ├── supervised_example_1k_Qhat.txt │ │ └── supervised_example_1k_V.txt │ └── unsupervised │ │ ├── unsupervised_example_1k_Phat.txt │ │ ├── unsupervised_example_1k_Qhat.txt │ │ └── unsupervised_example_1k_V.txt ├── run_scope_examples.sh └── source_files │ ├── example_1k.bed │ ├── example_1k.bim │ ├── example_1k.fam │ ├── example_1k.plink.freq │ ├── example_1k_allele_frequencies.txt │ └── example_1k_proportions.txt ├── include ├── Eigen │ ├── Cholesky │ ├── CholmodSupport │ ├── Core │ ├── Dense │ ├── Eigen │ ├── Eigenvalues │ ├── Geometry │ ├── Householder │ ├── IterativeLinearSolvers │ ├── Jacobi │ ├── LU │ ├── MetisSupport │ ├── OrderingMethods │ ├── PaStiXSupport │ ├── PardisoSupport │ ├── QR │ ├── QtAlignedMalloc │ ├── SPQRSupport │ ├── SVD │ ├── Sparse │ ├── SparseCholesky │ ├── SparseCore │ ├── SparseLU │ ├── SparseQR │ ├── StdDeque │ ├── StdList │ ├── StdVector │ ├── SuperLUSupport │ ├── UmfPackSupport │ └── src │ │ ├── Cholesky │ │ ├── LDLT.h │ │ ├── LLT.h │ │ └── LLT_LAPACKE.h │ │ ├── CholmodSupport │ │ └── CholmodSupport.h │ │ ├── Core │ │ ├── Array.h │ │ ├── ArrayBase.h │ │ ├── ArrayWrapper.h │ │ ├── Assign.h │ │ ├── AssignEvaluator.h │ │ ├── Assign_MKL.h │ │ ├── BandMatrix.h │ │ ├── Block.h │ │ ├── BooleanRedux.h │ │ ├── CommaInitializer.h │ │ ├── ConditionEstimator.h │ │ ├── CoreEvaluators.h │ │ ├── CoreIterators.h │ │ ├── CwiseBinaryOp.h │ │ ├── CwiseNullaryOp.h │ │ ├── CwiseTernaryOp.h │ │ ├── CwiseUnaryOp.h │ │ ├── CwiseUnaryView.h │ │ ├── DenseBase.h │ │ ├── DenseCoeffsBase.h │ │ ├── DenseStorage.h │ │ ├── Diagonal.h │ │ ├── DiagonalMatrix.h │ │ ├── DiagonalProduct.h │ │ ├── Dot.h │ │ ├── EigenBase.h │ │ ├── ForceAlignedAccess.h │ │ ├── Fuzzy.h │ │ ├── GeneralProduct.h │ │ ├── GenericPacketMath.h │ │ ├── GlobalFunctions.h │ │ ├── IO.h │ │ ├── Inverse.h │ │ ├── Map.h │ │ ├── MapBase.h │ │ ├── MathFunctions.h │ │ ├── MathFunctionsImpl.h │ │ ├── Matrix.h │ │ ├── MatrixBase.h │ │ ├── NestByValue.h │ │ ├── NoAlias.h │ │ ├── NumTraits.h │ │ ├── PermutationMatrix.h │ │ ├── PlainObjectBase.h │ │ ├── Product.h │ │ ├── ProductEvaluators.h │ │ ├── Random.h │ │ ├── Redux.h │ │ ├── Ref.h │ │ ├── Replicate.h │ │ ├── ReturnByValue.h │ │ ├── Reverse.h │ │ ├── Select.h │ │ ├── SelfAdjointView.h │ │ ├── SelfCwiseBinaryOp.h │ │ ├── Solve.h │ │ ├── SolveTriangular.h │ │ ├── SolverBase.h │ │ ├── StableNorm.h │ │ ├── Stride.h │ │ ├── Swap.h │ │ ├── Transpose.h │ │ ├── Transpositions.h │ │ ├── TriangularMatrix.h │ │ ├── VectorBlock.h │ │ ├── VectorwiseOp.h │ │ ├── Visitor.h │ │ ├── arch │ │ │ ├── AVX │ │ │ │ ├── Complex.h │ │ │ │ ├── MathFunctions.h │ │ │ │ ├── PacketMath.h │ │ │ │ └── TypeCasting.h │ │ │ ├── AVX512 │ │ │ │ ├── MathFunctions.h │ │ │ │ └── PacketMath.h │ │ │ ├── AltiVec │ │ │ │ ├── Complex.h │ │ │ │ ├── MathFunctions.h │ │ │ │ └── PacketMath.h │ │ │ ├── CUDA │ │ │ │ ├── Complex.h │ │ │ │ ├── Half.h │ │ │ │ ├── MathFunctions.h │ │ │ │ ├── PacketMath.h │ │ │ │ ├── PacketMathHalf.h │ │ │ │ └── TypeCasting.h │ │ │ ├── Default │ │ │ │ └── Settings.h │ │ │ ├── NEON │ │ │ │ ├── Complex.h │ │ │ │ ├── MathFunctions.h │ │ │ │ └── PacketMath.h │ │ │ ├── SSE │ │ │ │ ├── Complex.h │ │ │ │ ├── MathFunctions.h │ │ │ │ ├── PacketMath.h │ │ │ │ └── TypeCasting.h │ │ │ └── ZVector │ │ │ │ ├── Complex.h │ │ │ │ ├── MathFunctions.h │ │ │ │ └── PacketMath.h │ │ ├── functors │ │ │ ├── AssignmentFunctors.h │ │ │ ├── BinaryFunctors.h │ │ │ ├── NullaryFunctors.h │ │ │ ├── StlFunctors.h │ │ │ ├── TernaryFunctors.h │ │ │ └── UnaryFunctors.h │ │ ├── products │ │ │ ├── GeneralBlockPanelKernel.h │ │ │ ├── GeneralMatrixMatrix.h │ │ │ ├── GeneralMatrixMatrixTriangular.h │ │ │ ├── GeneralMatrixMatrixTriangular_BLAS.h │ │ │ ├── GeneralMatrixMatrix_BLAS.h │ │ │ ├── GeneralMatrixVector.h │ │ │ ├── GeneralMatrixVector_BLAS.h │ │ │ ├── Parallelizer.h │ │ │ ├── SelfadjointMatrixMatrix.h │ │ │ ├── SelfadjointMatrixMatrix_BLAS.h │ │ │ ├── SelfadjointMatrixVector.h │ │ │ ├── SelfadjointMatrixVector_BLAS.h │ │ │ ├── SelfadjointProduct.h │ │ │ ├── SelfadjointRank2Update.h │ │ │ ├── TriangularMatrixMatrix.h │ │ │ ├── TriangularMatrixMatrix_BLAS.h │ │ │ ├── TriangularMatrixVector.h │ │ │ ├── TriangularMatrixVector_BLAS.h │ │ │ ├── TriangularSolverMatrix.h │ │ │ ├── TriangularSolverMatrix_BLAS.h │ │ │ └── TriangularSolverVector.h │ │ └── util │ │ │ ├── BlasUtil.h │ │ │ ├── Constants.h │ │ │ ├── DisableStupidWarnings.h │ │ │ ├── ForwardDeclarations.h │ │ │ ├── MKL_support.h │ │ │ ├── Macros.h │ │ │ ├── Memory.h │ │ │ ├── Meta.h │ │ │ ├── NonMPL2.h │ │ │ ├── ReenableStupidWarnings.h │ │ │ ├── StaticAssert.h │ │ │ └── XprHelper.h │ │ ├── Eigenvalues │ │ ├── ComplexEigenSolver.h │ │ ├── ComplexSchur.h │ │ ├── ComplexSchur_LAPACKE.h │ │ ├── EigenSolver.h │ │ ├── GeneralizedEigenSolver.h │ │ ├── GeneralizedSelfAdjointEigenSolver.h │ │ ├── HessenbergDecomposition.h │ │ ├── MatrixBaseEigenvalues.h │ │ ├── RealQZ.h │ │ ├── RealSchur.h │ │ ├── RealSchur_LAPACKE.h │ │ ├── SelfAdjointEigenSolver.h │ │ ├── SelfAdjointEigenSolver_LAPACKE.h │ │ └── Tridiagonalization.h │ │ ├── Geometry │ │ ├── AlignedBox.h │ │ ├── AngleAxis.h │ │ ├── EulerAngles.h │ │ ├── Homogeneous.h │ │ ├── Hyperplane.h │ │ ├── OrthoMethods.h │ │ ├── ParametrizedLine.h │ │ ├── Quaternion.h │ │ ├── Rotation2D.h │ │ ├── RotationBase.h │ │ ├── Scaling.h │ │ ├── Transform.h │ │ ├── Translation.h │ │ ├── Umeyama.h │ │ └── arch │ │ │ └── Geometry_SSE.h │ │ ├── Householder │ │ ├── BlockHouseholder.h │ │ ├── Householder.h │ │ └── HouseholderSequence.h │ │ ├── IterativeLinearSolvers │ │ ├── BasicPreconditioners.h │ │ ├── BiCGSTAB.h │ │ ├── ConjugateGradient.h │ │ ├── IncompleteCholesky.h │ │ ├── IncompleteLUT.h │ │ ├── IterativeSolverBase.h │ │ ├── LeastSquareConjugateGradient.h │ │ └── SolveWithGuess.h │ │ ├── Jacobi │ │ └── Jacobi.h │ │ ├── LU │ │ ├── Determinant.h │ │ ├── FullPivLU.h │ │ ├── InverseImpl.h │ │ ├── PartialPivLU.h │ │ ├── PartialPivLU_LAPACKE.h │ │ └── arch │ │ │ └── Inverse_SSE.h │ │ ├── MetisSupport │ │ └── MetisSupport.h │ │ ├── OrderingMethods │ │ ├── Amd.h │ │ ├── Eigen_Colamd.h │ │ └── Ordering.h │ │ ├── PaStiXSupport │ │ └── PaStiXSupport.h │ │ ├── PardisoSupport │ │ └── PardisoSupport.h │ │ ├── QR │ │ ├── ColPivHouseholderQR.h │ │ ├── ColPivHouseholderQR_LAPACKE.h │ │ ├── CompleteOrthogonalDecomposition.h │ │ ├── FullPivHouseholderQR.h │ │ ├── HouseholderQR.h │ │ └── HouseholderQR_LAPACKE.h │ │ ├── SPQRSupport │ │ └── SuiteSparseQRSupport.h │ │ ├── SVD │ │ ├── BDCSVD.h │ │ ├── JacobiSVD.h │ │ ├── JacobiSVD_LAPACKE.h │ │ ├── SVDBase.h │ │ └── UpperBidiagonalization.h │ │ ├── SparseCholesky │ │ ├── SimplicialCholesky.h │ │ └── SimplicialCholesky_impl.h │ │ ├── SparseCore │ │ ├── AmbiVector.h │ │ ├── CompressedStorage.h │ │ ├── ConservativeSparseSparseProduct.h │ │ ├── MappedSparseMatrix.h │ │ ├── SparseAssign.h │ │ ├── SparseBlock.h │ │ ├── SparseColEtree.h │ │ ├── SparseCompressedBase.h │ │ ├── SparseCwiseBinaryOp.h │ │ ├── SparseCwiseUnaryOp.h │ │ ├── SparseDenseProduct.h │ │ ├── SparseDiagonalProduct.h │ │ ├── SparseDot.h │ │ ├── SparseFuzzy.h │ │ ├── SparseMap.h │ │ ├── SparseMatrix.h │ │ ├── SparseMatrixBase.h │ │ ├── SparsePermutation.h │ │ ├── SparseProduct.h │ │ ├── SparseRedux.h │ │ ├── SparseRef.h │ │ ├── SparseSelfAdjointView.h │ │ ├── SparseSolverBase.h │ │ ├── SparseSparseProductWithPruning.h │ │ ├── SparseTranspose.h │ │ ├── SparseTriangularView.h │ │ ├── SparseUtil.h │ │ ├── SparseVector.h │ │ ├── SparseView.h │ │ └── TriangularSolver.h │ │ ├── SparseLU │ │ ├── SparseLU.h │ │ ├── SparseLUImpl.h │ │ ├── SparseLU_Memory.h │ │ ├── SparseLU_Structs.h │ │ ├── SparseLU_SupernodalMatrix.h │ │ ├── SparseLU_Utils.h │ │ ├── SparseLU_column_bmod.h │ │ ├── SparseLU_column_dfs.h │ │ ├── SparseLU_copy_to_ucol.h │ │ ├── SparseLU_gemm_kernel.h │ │ ├── SparseLU_heap_relax_snode.h │ │ ├── SparseLU_kernel_bmod.h │ │ ├── SparseLU_panel_bmod.h │ │ ├── SparseLU_panel_dfs.h │ │ ├── SparseLU_pivotL.h │ │ ├── SparseLU_pruneL.h │ │ └── SparseLU_relax_snode.h │ │ ├── SparseQR │ │ └── SparseQR.h │ │ ├── StlSupport │ │ ├── StdDeque.h │ │ ├── StdList.h │ │ ├── StdVector.h │ │ └── details.h │ │ ├── SuperLUSupport │ │ └── SuperLUSupport.h │ │ ├── UmfPackSupport │ │ └── UmfPackSupport.h │ │ ├── misc │ │ ├── Image.h │ │ ├── Kernel.h │ │ ├── RealSvd2x2.h │ │ ├── blas.h │ │ ├── lapack.h │ │ ├── lapacke.h │ │ └── lapacke_mangling.h │ │ └── plugins │ │ ├── ArrayCwiseBinaryOps.h │ │ ├── ArrayCwiseUnaryOps.h │ │ ├── BlockMethods.h │ │ ├── CommonCwiseBinaryOps.h │ │ ├── CommonCwiseUnaryOps.h │ │ ├── MatrixCwiseBinaryOps.h │ │ └── MatrixCwiseUnaryOps.h ├── Spectra │ ├── GenEigsBase.h │ ├── GenEigsComplexShiftSolver.h │ ├── GenEigsRealShiftSolver.h │ ├── GenEigsSolver.h │ ├── LinAlg │ │ ├── Arnoldi.h │ │ ├── BKLDLT.h │ │ ├── DoubleShiftQR.h │ │ ├── Lanczos.h │ │ ├── TridiagEigen.h │ │ ├── UpperHessenbergEigen.h │ │ └── UpperHessenbergQR.h │ ├── MatOp │ │ ├── DenseCholesky.h │ │ ├── DenseGenComplexShiftSolve.h │ │ ├── DenseGenMatProd.h │ │ ├── DenseGenRealShiftSolve.h │ │ ├── DenseSymMatProd.h │ │ ├── DenseSymShiftSolve.h │ │ ├── SparseCholesky.h │ │ ├── SparseGenMatProd.h │ │ ├── SparseGenRealShiftSolve.h │ │ ├── SparseRegularInverse.h │ │ ├── SparseSymMatProd.h │ │ ├── SparseSymShiftSolve.h │ │ └── internal │ │ │ ├── ArnoldiOp.h │ │ │ ├── SymGEigsCholeskyOp.h │ │ │ └── SymGEigsRegInvOp.h │ ├── SymEigsBase.h │ ├── SymEigsShiftSolver.h │ ├── SymEigsSolver.h │ ├── SymGEigsSolver.h │ ├── Util │ │ ├── CompInfo.h │ │ ├── GEigsMode.h │ │ ├── SelectionRule.h │ │ ├── SimpleRandom.h │ │ └── TypeTraits.h │ └── contrib │ │ ├── LOBPCGSolver.h │ │ └── PartialSVDSolver.h ├── alstructure.h ├── config.h ├── genotype.h ├── helper.h ├── mailman.h ├── matmult.h └── storage.h ├── misc ├── assessment │ ├── README.md │ ├── example_viz.png │ ├── metrics.R │ └── visualize.R ├── real_data │ ├── HGDP │ │ ├── get_HGDP.sh │ │ └── hgdp_param.txt.gz │ ├── HO │ │ ├── convertf │ │ ├── ho_remove.samps │ │ └── prepare_ho.sh │ ├── README.md │ ├── TGP │ │ ├── TGP_unrel.txt │ │ ├── gen_tgp_plink_metrics.sh │ │ ├── get_tgp.sh │ │ ├── tgp_pops.txt │ │ └── tgp_super_pops.txt │ └── UKB │ │ ├── long_range_ld.filter │ │ └── prepare_ukb.sh └── simulations │ ├── README.md │ ├── generate_plink_frq.py │ ├── generate_simulations_python.sh │ ├── install_packages.sh │ ├── simulateA.py │ └── simulateB.py └── src ├── alstructure.cpp ├── genotype.cpp ├── matmult.cpp ├── run_alstructure.cpp └── storage.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | /* 2 | !CMakeLists.txt 3 | !/examples 4 | !/.git 5 | !/.gitignore 6 | !/include 7 | !LICENSE 8 | !README.md 9 | !/src 10 | !/misc 11 | */.vscode 12 | .DS_Store 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(SCOPE) 3 | 4 | include_directories(include/) 5 | 6 | if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") 7 | set(CMAKE_CXX_FLAGS "-std=c++0x -O3") 8 | else() 9 | set(CMAKE_CXX_FLAGS "-std=c++0x -O3 -lrt -pthread") 10 | endif() 11 | 12 | IF (NOT DEFINED SSE_SUPPORT) 13 | SET(SSE_SUPPORT 0) 14 | ENDIF() 15 | ADD_DEFINITIONS(-DSSE_SUPPORT=${SSE_SUPPORT}) 16 | 17 | IF (NOT DEFINED DEBUG) 18 | SET(DEBUG 0) 19 | ENDIF() 20 | ADD_DEFINITIONS(-DDEBUG=${DEBUG}) 21 | 22 | add_executable(scope src/run_alstructure.cpp src/alstructure.cpp src/matmult.cpp src/genotype.cpp src/storage.cpp) 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SCOPE - (SCalable pOPulation structure inferencE) 2 | 3 | SCOPE is a method for performing scalable population structure inference on biobank-scale genomic data. SCOPE utilizes a likelihood-free framework that involves estimation of the individual allele frequency (IAF) matrix through a modified version of principal component analysis (PCA) known as latent subspace estimation (LSE) followed by alternating least squares (ALS) to transform the estimated IAF matrix into ancestral allele frequencies and admixture proportions. SCOPE utilizes two major optimizations to enable scalable inference. Firstly, SCOPE uses randomized eigendecomposition to efficiently estimate the latent subspace. Second, SCOPE uses the Mailman algorithm for fast matrix-vector multiplication involving the genotype matrix. 4 | 5 | ## License 6 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 7 | 8 | This code is based on contributions from the following sources: 9 | * [Eigen](http://eigen.tuxfamily.org/) - C++ template library for linear algebra 10 | * [Spectra](https://spectralib.org/) - C++ Library For Large Scale Eigenvalue Problems 11 | * [ProPCA](https://github.com/sriramlab/ProPCA) - Scalable probabilistic PCA for large-scale genetic variation data 12 | 13 | ## Prerequisites 14 | 15 | The following packages are required on a Linux machine to compile and use SCOPE. 16 | 17 | ``` 18 | g++ (>=4.5) 19 | cmake (>=2.8.12) 20 | make (>=3.81) 21 | ``` 22 | SCOPE has been tested on CentOS 6.10 and 7, g++ 4.8.5 and 4.9.3, make 3.81 and 3.82, and cmake 2.8.12.2 and 3.7.2. 23 | 24 | ## Installing 25 | 26 | To install SCOPE, run the following commands: 27 | 28 | ``` 29 | git clone https://github.com/sriramlab/SCOPE.git 30 | cd SCOPE 31 | mkdir build 32 | cd build 33 | cmake .. 34 | make 35 | ``` 36 | 37 | SCOPE should finish compiling within a few minutes. An example script can be found in the `examples` subdirectory to test SCOPE. We have additionally included several scripts that can regenerate the simulations and real datasets we used in our manuscript. Please see the subdirectories in `misc` for more detail. 38 | 39 | ## Documentation for SCOPE 40 | 41 | ### Parameters 42 | 43 | SCOPE can be run the from the command line using the following options. At minimum, SCOPE requires the path to the PLINK binary prefix. 44 | 45 | ``` 46 | * genotype (-g) : Path to PLINK binary prefix 47 | * frequencies (-freq) : Path to PLINK frequency file for supervision (default: none) 48 | * num_evec (-k) : Number of latent populations (default: 5) 49 | * max_iterations (-m) : Maximum number of iterations for ALS (default: 1000) 50 | * convergence_limit (-cl) : Convergence threshold for LSE and ALS (default: 0.00001) 51 | * output_path (-o) : Output prefix (default: scope_) 52 | * nthreads (-nt): Number of threads to use (default: 1) 53 | * seed (-seed): Seed to use (default: system time) 54 | ``` 55 | 56 | To perform supervised population structure inference, provide the `-freq` parameter. The file needed for this parameter can be generated using `plink --freq --within`. If no frequency file is provided, SCOPE will perform unsupervised population structure inference. When using the supervised mode, be sure to make sure that the ordering of the SNPs match between the frequency file and the target dataset. Alleles much also be coded consistently between the two. One can flip alleles using the `--flip` and `--flip-subset` commands in PLINK. 57 | 58 | ### Output 59 | 60 | SCOPE will output the following files: 61 | 62 | * `scope_V.txt`: the estimated latent subspace from LSE 63 | * `scope_Phat.txt`: the estimated allele frequencies for the latent populations 64 | * `scope_Qhat.txt`: the estimated admixture proportions for each individual 65 | 66 | Each column of `Phat.txt` corresponds to a row of `Qhat.txt`. If `Qhat.txt` is transposed, the columns will correspond to the columns of `Phat.txt`. If running SCOPE in supervised mode, the order of the columns in `Phat.txt` corresponds to the order displayed in the PLINK frequency file. 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | ## Example Files 2 | 3 | We provide example source files in `source_files`. The script `run_scope_examples.sh` will run SCOPE both unsupervised and supervised. The script should complete almost immediately, but may need to be modified to correctly point to the path of your SCOPE binary. Expected output from this script can be found in `results` under their respective folders. 4 | 5 | ### Source Files 6 | 7 | The example files in `source_files` were generated using the `simulateA.py` script found in `misc/simulations` from the root of the repository. The PLINK formatted frequency file was generated using the `generate_plink_frq.py` script found in `misc/simulations` from the root of the repository. 8 | 9 | #### Contents 10 | 11 | + Example PLINK binary files: `example_1k.bed/bim/fam` 12 | + True allele frequencies: `example_1k_allele_frequencies.txt` 13 | + True proportions: `example_1k_proportions.txt` 14 | + True frequencies in PLINK format: `example_1k.plink.freq` 15 | 16 | ### Results 17 | 18 | The `results` subdirectory contains the expected output from running `run_scope_example.sh`. 19 | 20 | + `*_Phat.txt` are the estimated minor allele frequencies 21 | + `*_V.txt` is the estimated latent subspace 22 | + `*_Qhat.txt` is the estimated admixture proportions 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/run_scope_examples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | # Path to SCOPE binary 4 | scope_binary=../build/scope 5 | 6 | # Run SCOPE unsupervised 7 | $scope_binary -g source_files/example_1k -k 6 -seed 12345 -o unsupervised_example_1k_ 8 | 9 | # Run SCOPE supervised 10 | $scope_binary -g source_files/example_1k -k 6 -seed 12345 -freq source_files/example_1k.plink.freq -o supervised_example_1k_ 11 | -------------------------------------------------------------------------------- /examples/source_files/example_1k.bed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sriramlab/SCOPE/e09c6546c67915f87d9aaf2581fbb300ad9c47a3/examples/source_files/example_1k.bed -------------------------------------------------------------------------------- /include/Eigen/Cholesky: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_CHOLESKY_MODULE_H 9 | #define EIGEN_CHOLESKY_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** \defgroup Cholesky_Module Cholesky module 16 | * 17 | * 18 | * 19 | * This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices. 20 | * Those decompositions are also accessible via the following methods: 21 | * - MatrixBase::llt() 22 | * - MatrixBase::ldlt() 23 | * - SelfAdjointView::llt() 24 | * - SelfAdjointView::ldlt() 25 | * 26 | * \code 27 | * #include 28 | * \endcode 29 | */ 30 | 31 | #include "src/Cholesky/LLT.h" 32 | #include "src/Cholesky/LDLT.h" 33 | #ifdef EIGEN_USE_LAPACKE 34 | #include "src/misc/lapacke.h" 35 | #include "src/Cholesky/LLT_LAPACKE.h" 36 | #endif 37 | 38 | #include "src/Core/util/ReenableStupidWarnings.h" 39 | 40 | #endif // EIGEN_CHOLESKY_MODULE_H 41 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 42 | -------------------------------------------------------------------------------- /include/Eigen/CholmodSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_CHOLMODSUPPORT_MODULE_H 9 | #define EIGEN_CHOLMODSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | extern "C" { 16 | #include 17 | } 18 | 19 | /** \ingroup Support_modules 20 | * \defgroup CholmodSupport_Module CholmodSupport module 21 | * 22 | * This module provides an interface to the Cholmod library which is part of the suitesparse package. 23 | * It provides the two following main factorization classes: 24 | * - class CholmodSupernodalLLT: a supernodal LLT Cholesky factorization. 25 | * - class CholmodDecomposiiton: a general L(D)LT Cholesky factorization with automatic or explicit runtime selection of the underlying factorization method (supernodal or simplicial). 26 | * 27 | * For the sake of completeness, this module also propose the two following classes: 28 | * - class CholmodSimplicialLLT 29 | * - class CholmodSimplicialLDLT 30 | * Note that these classes does not bring any particular advantage compared to the built-in 31 | * SimplicialLLT and SimplicialLDLT factorization classes. 32 | * 33 | * \code 34 | * #include 35 | * \endcode 36 | * 37 | * In order to use this module, the cholmod headers must be accessible from the include paths, and your binary must be linked to the cholmod library and its dependencies. 38 | * The dependencies depend on how cholmod has been compiled. 39 | * For a cmake based project, you can use our FindCholmod.cmake module to help you in this task. 40 | * 41 | */ 42 | 43 | #include "src/CholmodSupport/CholmodSupport.h" 44 | 45 | #include "src/Core/util/ReenableStupidWarnings.h" 46 | 47 | #endif // EIGEN_CHOLMODSUPPORT_MODULE_H 48 | 49 | -------------------------------------------------------------------------------- /include/Eigen/Dense: -------------------------------------------------------------------------------- 1 | #include "Core" 2 | #include "LU" 3 | #include "Cholesky" 4 | #include "QR" 5 | #include "SVD" 6 | #include "Geometry" 7 | #include "Eigenvalues" 8 | -------------------------------------------------------------------------------- /include/Eigen/Eigen: -------------------------------------------------------------------------------- 1 | #include "Dense" 2 | #include "Sparse" 3 | -------------------------------------------------------------------------------- /include/Eigen/Eigenvalues: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_EIGENVALUES_MODULE_H 9 | #define EIGEN_EIGENVALUES_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include "Cholesky" 16 | #include "Jacobi" 17 | #include "Householder" 18 | #include "LU" 19 | #include "Geometry" 20 | 21 | /** \defgroup Eigenvalues_Module Eigenvalues module 22 | * 23 | * 24 | * 25 | * This module mainly provides various eigenvalue solvers. 26 | * This module also provides some MatrixBase methods, including: 27 | * - MatrixBase::eigenvalues(), 28 | * - MatrixBase::operatorNorm() 29 | * 30 | * \code 31 | * #include 32 | * \endcode 33 | */ 34 | 35 | #include "src/misc/RealSvd2x2.h" 36 | #include "src/Eigenvalues/Tridiagonalization.h" 37 | #include "src/Eigenvalues/RealSchur.h" 38 | #include "src/Eigenvalues/EigenSolver.h" 39 | #include "src/Eigenvalues/SelfAdjointEigenSolver.h" 40 | #include "src/Eigenvalues/GeneralizedSelfAdjointEigenSolver.h" 41 | #include "src/Eigenvalues/HessenbergDecomposition.h" 42 | #include "src/Eigenvalues/ComplexSchur.h" 43 | #include "src/Eigenvalues/ComplexEigenSolver.h" 44 | #include "src/Eigenvalues/RealQZ.h" 45 | #include "src/Eigenvalues/GeneralizedEigenSolver.h" 46 | #include "src/Eigenvalues/MatrixBaseEigenvalues.h" 47 | #ifdef EIGEN_USE_LAPACKE 48 | #include "src/misc/lapacke.h" 49 | #include "src/Eigenvalues/RealSchur_LAPACKE.h" 50 | #include "src/Eigenvalues/ComplexSchur_LAPACKE.h" 51 | #include "src/Eigenvalues/SelfAdjointEigenSolver_LAPACKE.h" 52 | #endif 53 | 54 | #include "src/Core/util/ReenableStupidWarnings.h" 55 | 56 | #endif // EIGEN_EIGENVALUES_MODULE_H 57 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 58 | -------------------------------------------------------------------------------- /include/Eigen/Geometry: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_GEOMETRY_MODULE_H 9 | #define EIGEN_GEOMETRY_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include "SVD" 16 | #include "LU" 17 | #include 18 | 19 | /** \defgroup Geometry_Module Geometry module 20 | * 21 | * This module provides support for: 22 | * - fixed-size homogeneous transformations 23 | * - translation, scaling, 2D and 3D rotations 24 | * - \link Quaternion quaternions \endlink 25 | * - cross products (\ref MatrixBase::cross, \ref MatrixBase::cross3) 26 | * - orthognal vector generation (\ref MatrixBase::unitOrthogonal) 27 | * - some linear components: \link ParametrizedLine parametrized-lines \endlink and \link Hyperplane hyperplanes \endlink 28 | * - \link AlignedBox axis aligned bounding boxes \endlink 29 | * - \link umeyama least-square transformation fitting \endlink 30 | * 31 | * \code 32 | * #include 33 | * \endcode 34 | */ 35 | 36 | #include "src/Geometry/OrthoMethods.h" 37 | #include "src/Geometry/EulerAngles.h" 38 | 39 | #include "src/Geometry/Homogeneous.h" 40 | #include "src/Geometry/RotationBase.h" 41 | #include "src/Geometry/Rotation2D.h" 42 | #include "src/Geometry/Quaternion.h" 43 | #include "src/Geometry/AngleAxis.h" 44 | #include "src/Geometry/Transform.h" 45 | #include "src/Geometry/Translation.h" 46 | #include "src/Geometry/Scaling.h" 47 | #include "src/Geometry/Hyperplane.h" 48 | #include "src/Geometry/ParametrizedLine.h" 49 | #include "src/Geometry/AlignedBox.h" 50 | #include "src/Geometry/Umeyama.h" 51 | 52 | // Use the SSE optimized version whenever possible. At the moment the 53 | // SSE version doesn't compile when AVX is enabled 54 | #if defined EIGEN_VECTORIZE_SSE && !defined EIGEN_VECTORIZE_AVX 55 | #include "src/Geometry/arch/Geometry_SSE.h" 56 | #endif 57 | 58 | #include "src/Core/util/ReenableStupidWarnings.h" 59 | 60 | #endif // EIGEN_GEOMETRY_MODULE_H 61 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 62 | 63 | -------------------------------------------------------------------------------- /include/Eigen/Householder: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_HOUSEHOLDER_MODULE_H 9 | #define EIGEN_HOUSEHOLDER_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** \defgroup Householder_Module Householder module 16 | * This module provides Householder transformations. 17 | * 18 | * \code 19 | * #include 20 | * \endcode 21 | */ 22 | 23 | #include "src/Householder/Householder.h" 24 | #include "src/Householder/HouseholderSequence.h" 25 | #include "src/Householder/BlockHouseholder.h" 26 | 27 | #include "src/Core/util/ReenableStupidWarnings.h" 28 | 29 | #endif // EIGEN_HOUSEHOLDER_MODULE_H 30 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 31 | -------------------------------------------------------------------------------- /include/Eigen/IterativeLinearSolvers: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_ITERATIVELINEARSOLVERS_MODULE_H 9 | #define EIGEN_ITERATIVELINEARSOLVERS_MODULE_H 10 | 11 | #include "SparseCore" 12 | #include "OrderingMethods" 13 | 14 | #include "src/Core/util/DisableStupidWarnings.h" 15 | 16 | /** 17 | * \defgroup IterativeLinearSolvers_Module IterativeLinearSolvers module 18 | * 19 | * This module currently provides iterative methods to solve problems of the form \c A \c x = \c b, where \c A is a squared matrix, usually very large and sparse. 20 | * Those solvers are accessible via the following classes: 21 | * - ConjugateGradient for selfadjoint (hermitian) matrices, 22 | * - LeastSquaresConjugateGradient for rectangular least-square problems, 23 | * - BiCGSTAB for general square matrices. 24 | * 25 | * These iterative solvers are associated with some preconditioners: 26 | * - IdentityPreconditioner - not really useful 27 | * - DiagonalPreconditioner - also called Jacobi preconditioner, work very well on diagonal dominant matrices. 28 | * - IncompleteLUT - incomplete LU factorization with dual thresholding 29 | * 30 | * Such problems can also be solved using the direct sparse decomposition modules: SparseCholesky, CholmodSupport, UmfPackSupport, SuperLUSupport. 31 | * 32 | \code 33 | #include 34 | \endcode 35 | */ 36 | 37 | #include "src/IterativeLinearSolvers/SolveWithGuess.h" 38 | #include "src/IterativeLinearSolvers/IterativeSolverBase.h" 39 | #include "src/IterativeLinearSolvers/BasicPreconditioners.h" 40 | #include "src/IterativeLinearSolvers/ConjugateGradient.h" 41 | #include "src/IterativeLinearSolvers/LeastSquareConjugateGradient.h" 42 | #include "src/IterativeLinearSolvers/BiCGSTAB.h" 43 | #include "src/IterativeLinearSolvers/IncompleteLUT.h" 44 | #include "src/IterativeLinearSolvers/IncompleteCholesky.h" 45 | 46 | #include "src/Core/util/ReenableStupidWarnings.h" 47 | 48 | #endif // EIGEN_ITERATIVELINEARSOLVERS_MODULE_H 49 | -------------------------------------------------------------------------------- /include/Eigen/Jacobi: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_JACOBI_MODULE_H 9 | #define EIGEN_JACOBI_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** \defgroup Jacobi_Module Jacobi module 16 | * This module provides Jacobi and Givens rotations. 17 | * 18 | * \code 19 | * #include 20 | * \endcode 21 | * 22 | * In addition to listed classes, it defines the two following MatrixBase methods to apply a Jacobi or Givens rotation: 23 | * - MatrixBase::applyOnTheLeft() 24 | * - MatrixBase::applyOnTheRight(). 25 | */ 26 | 27 | #include "src/Jacobi/Jacobi.h" 28 | 29 | #include "src/Core/util/ReenableStupidWarnings.h" 30 | 31 | #endif // EIGEN_JACOBI_MODULE_H 32 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 33 | 34 | -------------------------------------------------------------------------------- /include/Eigen/LU: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_LU_MODULE_H 9 | #define EIGEN_LU_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** \defgroup LU_Module LU module 16 | * This module includes %LU decomposition and related notions such as matrix inversion and determinant. 17 | * This module defines the following MatrixBase methods: 18 | * - MatrixBase::inverse() 19 | * - MatrixBase::determinant() 20 | * 21 | * \code 22 | * #include 23 | * \endcode 24 | */ 25 | 26 | #include "src/misc/Kernel.h" 27 | #include "src/misc/Image.h" 28 | #include "src/LU/FullPivLU.h" 29 | #include "src/LU/PartialPivLU.h" 30 | #ifdef EIGEN_USE_LAPACKE 31 | #include "src/misc/lapacke.h" 32 | #include "src/LU/PartialPivLU_LAPACKE.h" 33 | #endif 34 | #include "src/LU/Determinant.h" 35 | #include "src/LU/InverseImpl.h" 36 | 37 | // Use the SSE optimized version whenever possible. At the moment the 38 | // SSE version doesn't compile when AVX is enabled 39 | #if defined EIGEN_VECTORIZE_SSE && !defined EIGEN_VECTORIZE_AVX 40 | #include "src/LU/arch/Inverse_SSE.h" 41 | #endif 42 | 43 | #include "src/Core/util/ReenableStupidWarnings.h" 44 | 45 | #endif // EIGEN_LU_MODULE_H 46 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 47 | -------------------------------------------------------------------------------- /include/Eigen/MetisSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_METISSUPPORT_MODULE_H 9 | #define EIGEN_METISSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | extern "C" { 16 | #include 17 | } 18 | 19 | 20 | /** \ingroup Support_modules 21 | * \defgroup MetisSupport_Module MetisSupport module 22 | * 23 | * \code 24 | * #include 25 | * \endcode 26 | * This module defines an interface to the METIS reordering package (http://glaros.dtc.umn.edu/gkhome/views/metis). 27 | * It can be used just as any other built-in method as explained in \link OrderingMethods_Module here. \endlink 28 | */ 29 | 30 | 31 | #include "src/MetisSupport/MetisSupport.h" 32 | 33 | #include "src/Core/util/ReenableStupidWarnings.h" 34 | 35 | #endif // EIGEN_METISSUPPORT_MODULE_H 36 | -------------------------------------------------------------------------------- /include/Eigen/OrderingMethods: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_ORDERINGMETHODS_MODULE_H 9 | #define EIGEN_ORDERINGMETHODS_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** 16 | * \defgroup OrderingMethods_Module OrderingMethods module 17 | * 18 | * This module is currently for internal use only 19 | * 20 | * It defines various built-in and external ordering methods for sparse matrices. 21 | * They are typically used to reduce the number of elements during 22 | * the sparse matrix decomposition (LLT, LU, QR). 23 | * Precisely, in a preprocessing step, a permutation matrix P is computed using 24 | * those ordering methods and applied to the columns of the matrix. 25 | * Using for instance the sparse Cholesky decomposition, it is expected that 26 | * the nonzeros elements in LLT(A*P) will be much smaller than that in LLT(A). 27 | * 28 | * 29 | * Usage : 30 | * \code 31 | * #include 32 | * \endcode 33 | * 34 | * A simple usage is as a template parameter in the sparse decomposition classes : 35 | * 36 | * \code 37 | * SparseLU > solver; 38 | * \endcode 39 | * 40 | * \code 41 | * SparseQR > solver; 42 | * \endcode 43 | * 44 | * It is possible as well to call directly a particular ordering method for your own purpose, 45 | * \code 46 | * AMDOrdering ordering; 47 | * PermutationMatrix perm; 48 | * SparseMatrix A; 49 | * //Fill the matrix ... 50 | * 51 | * ordering(A, perm); // Call AMD 52 | * \endcode 53 | * 54 | * \note Some of these methods (like AMD or METIS), need the sparsity pattern 55 | * of the input matrix to be symmetric. When the matrix is structurally unsymmetric, 56 | * Eigen computes internally the pattern of \f$A^T*A\f$ before calling the method. 57 | * If your matrix is already symmetric (at leat in structure), you can avoid that 58 | * by calling the method with a SelfAdjointView type. 59 | * 60 | * \code 61 | * // Call the ordering on the pattern of the lower triangular matrix A 62 | * ordering(A.selfadjointView(), perm); 63 | * \endcode 64 | */ 65 | 66 | #ifndef EIGEN_MPL2_ONLY 67 | #include "src/OrderingMethods/Amd.h" 68 | #endif 69 | 70 | #include "src/OrderingMethods/Ordering.h" 71 | #include "src/Core/util/ReenableStupidWarnings.h" 72 | 73 | #endif // EIGEN_ORDERINGMETHODS_MODULE_H 74 | -------------------------------------------------------------------------------- /include/Eigen/PaStiXSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_PASTIXSUPPORT_MODULE_H 9 | #define EIGEN_PASTIXSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | extern "C" { 16 | #include 17 | #include 18 | } 19 | 20 | #ifdef complex 21 | #undef complex 22 | #endif 23 | 24 | /** \ingroup Support_modules 25 | * \defgroup PaStiXSupport_Module PaStiXSupport module 26 | * 27 | * This module provides an interface to the PaSTiX library. 28 | * PaSTiX is a general \b supernodal, \b parallel and \b opensource sparse solver. 29 | * It provides the two following main factorization classes: 30 | * - class PastixLLT : a supernodal, parallel LLt Cholesky factorization. 31 | * - class PastixLDLT: a supernodal, parallel LDLt Cholesky factorization. 32 | * - class PastixLU : a supernodal, parallel LU factorization (optimized for a symmetric pattern). 33 | * 34 | * \code 35 | * #include 36 | * \endcode 37 | * 38 | * In order to use this module, the PaSTiX headers must be accessible from the include paths, and your binary must be linked to the PaSTiX library and its dependencies. 39 | * The dependencies depend on how PaSTiX has been compiled. 40 | * For a cmake based project, you can use our FindPaSTiX.cmake module to help you in this task. 41 | * 42 | */ 43 | 44 | #include "src/PaStiXSupport/PaStiXSupport.h" 45 | 46 | #include "src/Core/util/ReenableStupidWarnings.h" 47 | 48 | #endif // EIGEN_PASTIXSUPPORT_MODULE_H 49 | -------------------------------------------------------------------------------- /include/Eigen/PardisoSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_PARDISOSUPPORT_MODULE_H 9 | #define EIGEN_PARDISOSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include 16 | 17 | /** \ingroup Support_modules 18 | * \defgroup PardisoSupport_Module PardisoSupport module 19 | * 20 | * This module brings support for the Intel(R) MKL PARDISO direct sparse solvers. 21 | * 22 | * \code 23 | * #include 24 | * \endcode 25 | * 26 | * In order to use this module, the MKL headers must be accessible from the include paths, and your binary must be linked to the MKL library and its dependencies. 27 | * See this \ref TopicUsingIntelMKL "page" for more information on MKL-Eigen integration. 28 | * 29 | */ 30 | 31 | #include "src/PardisoSupport/PardisoSupport.h" 32 | 33 | #include "src/Core/util/ReenableStupidWarnings.h" 34 | 35 | #endif // EIGEN_PARDISOSUPPORT_MODULE_H 36 | -------------------------------------------------------------------------------- /include/Eigen/QR: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_QR_MODULE_H 9 | #define EIGEN_QR_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include "Cholesky" 16 | #include "Jacobi" 17 | #include "Householder" 18 | 19 | /** \defgroup QR_Module QR module 20 | * 21 | * 22 | * 23 | * This module provides various QR decompositions 24 | * This module also provides some MatrixBase methods, including: 25 | * - MatrixBase::householderQr() 26 | * - MatrixBase::colPivHouseholderQr() 27 | * - MatrixBase::fullPivHouseholderQr() 28 | * 29 | * \code 30 | * #include 31 | * \endcode 32 | */ 33 | 34 | #include "src/QR/HouseholderQR.h" 35 | #include "src/QR/FullPivHouseholderQR.h" 36 | #include "src/QR/ColPivHouseholderQR.h" 37 | #include "src/QR/CompleteOrthogonalDecomposition.h" 38 | #ifdef EIGEN_USE_LAPACKE 39 | #include "src/misc/lapacke.h" 40 | #include "src/QR/HouseholderQR_LAPACKE.h" 41 | #include "src/QR/ColPivHouseholderQR_LAPACKE.h" 42 | #endif 43 | 44 | #include "src/Core/util/ReenableStupidWarnings.h" 45 | 46 | #endif // EIGEN_QR_MODULE_H 47 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 48 | -------------------------------------------------------------------------------- /include/Eigen/QtAlignedMalloc: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_QTMALLOC_MODULE_H 9 | #define EIGEN_QTMALLOC_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #if (!EIGEN_MALLOC_ALREADY_ALIGNED) 14 | 15 | #include "src/Core/util/DisableStupidWarnings.h" 16 | 17 | void *qMalloc(std::size_t size) 18 | { 19 | return Eigen::internal::aligned_malloc(size); 20 | } 21 | 22 | void qFree(void *ptr) 23 | { 24 | Eigen::internal::aligned_free(ptr); 25 | } 26 | 27 | void *qRealloc(void *ptr, std::size_t size) 28 | { 29 | void* newPtr = Eigen::internal::aligned_malloc(size); 30 | memcpy(newPtr, ptr, size); 31 | Eigen::internal::aligned_free(ptr); 32 | return newPtr; 33 | } 34 | 35 | #include "src/Core/util/ReenableStupidWarnings.h" 36 | 37 | #endif 38 | 39 | #endif // EIGEN_QTMALLOC_MODULE_H 40 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 41 | -------------------------------------------------------------------------------- /include/Eigen/SPQRSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SPQRSUPPORT_MODULE_H 9 | #define EIGEN_SPQRSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include "SuiteSparseQR.hpp" 16 | 17 | /** \ingroup Support_modules 18 | * \defgroup SPQRSupport_Module SuiteSparseQR module 19 | * 20 | * This module provides an interface to the SPQR library, which is part of the suitesparse package. 21 | * 22 | * \code 23 | * #include 24 | * \endcode 25 | * 26 | * In order to use this module, the SPQR headers must be accessible from the include paths, and your binary must be linked to the SPQR library and its dependencies (Cholmod, AMD, COLAMD,...). 27 | * For a cmake based project, you can use our FindSPQR.cmake and FindCholmod.Cmake modules 28 | * 29 | */ 30 | 31 | #include "src/CholmodSupport/CholmodSupport.h" 32 | #include "src/SPQRSupport/SuiteSparseQRSupport.h" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/Eigen/SVD: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SVD_MODULE_H 9 | #define EIGEN_SVD_MODULE_H 10 | 11 | #include "QR" 12 | #include "Householder" 13 | #include "Jacobi" 14 | 15 | #include "src/Core/util/DisableStupidWarnings.h" 16 | 17 | /** \defgroup SVD_Module SVD module 18 | * 19 | * 20 | * 21 | * This module provides SVD decomposition for matrices (both real and complex). 22 | * Two decomposition algorithms are provided: 23 | * - JacobiSVD implementing two-sided Jacobi iterations is numerically very accurate, fast for small matrices, but very slow for larger ones. 24 | * - BDCSVD implementing a recursive divide & conquer strategy on top of an upper-bidiagonalization which remains fast for large problems. 25 | * These decompositions are accessible via the respective classes and following MatrixBase methods: 26 | * - MatrixBase::jacobiSvd() 27 | * - MatrixBase::bdcSvd() 28 | * 29 | * \code 30 | * #include 31 | * \endcode 32 | */ 33 | 34 | #include "src/misc/RealSvd2x2.h" 35 | #include "src/SVD/UpperBidiagonalization.h" 36 | #include "src/SVD/SVDBase.h" 37 | #include "src/SVD/JacobiSVD.h" 38 | #include "src/SVD/BDCSVD.h" 39 | #if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT) 40 | #include "src/misc/lapacke.h" 41 | #include "src/SVD/JacobiSVD_LAPACKE.h" 42 | #endif 43 | 44 | #include "src/Core/util/ReenableStupidWarnings.h" 45 | 46 | #endif // EIGEN_SVD_MODULE_H 47 | /* vim: set filetype=cpp et sw=2 ts=2 ai: */ 48 | -------------------------------------------------------------------------------- /include/Eigen/Sparse: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SPARSE_MODULE_H 9 | #define EIGEN_SPARSE_MODULE_H 10 | 11 | /** \defgroup Sparse_Module Sparse meta-module 12 | * 13 | * Meta-module including all related modules: 14 | * - \ref SparseCore_Module 15 | * - \ref OrderingMethods_Module 16 | * - \ref SparseCholesky_Module 17 | * - \ref SparseLU_Module 18 | * - \ref SparseQR_Module 19 | * - \ref IterativeLinearSolvers_Module 20 | * 21 | \code 22 | #include 23 | \endcode 24 | */ 25 | 26 | #include "SparseCore" 27 | #include "OrderingMethods" 28 | #ifndef EIGEN_MPL2_ONLY 29 | #include "SparseCholesky" 30 | #endif 31 | #include "SparseLU" 32 | #include "SparseQR" 33 | #include "IterativeLinearSolvers" 34 | 35 | #endif // EIGEN_SPARSE_MODULE_H 36 | 37 | -------------------------------------------------------------------------------- /include/Eigen/SparseCholesky: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2013 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSECHOLESKY_MODULE_H 11 | #define EIGEN_SPARSECHOLESKY_MODULE_H 12 | 13 | #include "SparseCore" 14 | #include "OrderingMethods" 15 | 16 | #include "src/Core/util/DisableStupidWarnings.h" 17 | 18 | /** 19 | * \defgroup SparseCholesky_Module SparseCholesky module 20 | * 21 | * This module currently provides two variants of the direct sparse Cholesky decomposition for selfadjoint (hermitian) matrices. 22 | * Those decompositions are accessible via the following classes: 23 | * - SimplicialLLt, 24 | * - SimplicialLDLt 25 | * 26 | * Such problems can also be solved using the ConjugateGradient solver from the IterativeLinearSolvers module. 27 | * 28 | * \code 29 | * #include 30 | * \endcode 31 | */ 32 | 33 | #ifdef EIGEN_MPL2_ONLY 34 | #error The SparseCholesky module has nothing to offer in MPL2 only mode 35 | #endif 36 | 37 | #include "src/SparseCholesky/SimplicialCholesky.h" 38 | 39 | #ifndef EIGEN_MPL2_ONLY 40 | #include "src/SparseCholesky/SimplicialCholesky_impl.h" 41 | #endif 42 | 43 | #include "src/Core/util/ReenableStupidWarnings.h" 44 | 45 | #endif // EIGEN_SPARSECHOLESKY_MODULE_H 46 | -------------------------------------------------------------------------------- /include/Eigen/SparseCore: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SPARSECORE_MODULE_H 9 | #define EIGEN_SPARSECORE_MODULE_H 10 | 11 | #include "Core" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * \defgroup SparseCore_Module SparseCore module 23 | * 24 | * This module provides a sparse matrix representation, and basic associated matrix manipulations 25 | * and operations. 26 | * 27 | * See the \ref TutorialSparse "Sparse tutorial" 28 | * 29 | * \code 30 | * #include 31 | * \endcode 32 | * 33 | * This module depends on: Core. 34 | */ 35 | 36 | #include "src/SparseCore/SparseUtil.h" 37 | #include "src/SparseCore/SparseMatrixBase.h" 38 | #include "src/SparseCore/SparseAssign.h" 39 | #include "src/SparseCore/CompressedStorage.h" 40 | #include "src/SparseCore/AmbiVector.h" 41 | #include "src/SparseCore/SparseCompressedBase.h" 42 | #include "src/SparseCore/SparseMatrix.h" 43 | #include "src/SparseCore/SparseMap.h" 44 | #include "src/SparseCore/MappedSparseMatrix.h" 45 | #include "src/SparseCore/SparseVector.h" 46 | #include "src/SparseCore/SparseRef.h" 47 | #include "src/SparseCore/SparseCwiseUnaryOp.h" 48 | #include "src/SparseCore/SparseCwiseBinaryOp.h" 49 | #include "src/SparseCore/SparseTranspose.h" 50 | #include "src/SparseCore/SparseBlock.h" 51 | #include "src/SparseCore/SparseDot.h" 52 | #include "src/SparseCore/SparseRedux.h" 53 | #include "src/SparseCore/SparseView.h" 54 | #include "src/SparseCore/SparseDiagonalProduct.h" 55 | #include "src/SparseCore/ConservativeSparseSparseProduct.h" 56 | #include "src/SparseCore/SparseSparseProductWithPruning.h" 57 | #include "src/SparseCore/SparseProduct.h" 58 | #include "src/SparseCore/SparseDenseProduct.h" 59 | #include "src/SparseCore/SparseSelfAdjointView.h" 60 | #include "src/SparseCore/SparseTriangularView.h" 61 | #include "src/SparseCore/TriangularSolver.h" 62 | #include "src/SparseCore/SparsePermutation.h" 63 | #include "src/SparseCore/SparseFuzzy.h" 64 | #include "src/SparseCore/SparseSolverBase.h" 65 | 66 | #include "src/Core/util/ReenableStupidWarnings.h" 67 | 68 | #endif // EIGEN_SPARSECORE_MODULE_H 69 | 70 | -------------------------------------------------------------------------------- /include/Eigen/SparseLU: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2012 Désiré Nuentsa-Wakam 5 | // Copyright (C) 2012 Gael Guennebaud 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_SPARSELU_MODULE_H 12 | #define EIGEN_SPARSELU_MODULE_H 13 | 14 | #include "SparseCore" 15 | 16 | /** 17 | * \defgroup SparseLU_Module SparseLU module 18 | * This module defines a supernodal factorization of general sparse matrices. 19 | * The code is fully optimized for supernode-panel updates with specialized kernels. 20 | * Please, see the documentation of the SparseLU class for more details. 21 | */ 22 | 23 | // Ordering interface 24 | #include "OrderingMethods" 25 | 26 | #include "src/SparseLU/SparseLU_gemm_kernel.h" 27 | 28 | #include "src/SparseLU/SparseLU_Structs.h" 29 | #include "src/SparseLU/SparseLU_SupernodalMatrix.h" 30 | #include "src/SparseLU/SparseLUImpl.h" 31 | #include "src/SparseCore/SparseColEtree.h" 32 | #include "src/SparseLU/SparseLU_Memory.h" 33 | #include "src/SparseLU/SparseLU_heap_relax_snode.h" 34 | #include "src/SparseLU/SparseLU_relax_snode.h" 35 | #include "src/SparseLU/SparseLU_pivotL.h" 36 | #include "src/SparseLU/SparseLU_panel_dfs.h" 37 | #include "src/SparseLU/SparseLU_kernel_bmod.h" 38 | #include "src/SparseLU/SparseLU_panel_bmod.h" 39 | #include "src/SparseLU/SparseLU_column_dfs.h" 40 | #include "src/SparseLU/SparseLU_column_bmod.h" 41 | #include "src/SparseLU/SparseLU_copy_to_ucol.h" 42 | #include "src/SparseLU/SparseLU_pruneL.h" 43 | #include "src/SparseLU/SparseLU_Utils.h" 44 | #include "src/SparseLU/SparseLU.h" 45 | 46 | #endif // EIGEN_SPARSELU_MODULE_H 47 | -------------------------------------------------------------------------------- /include/Eigen/SparseQR: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SPARSEQR_MODULE_H 9 | #define EIGEN_SPARSEQR_MODULE_H 10 | 11 | #include "SparseCore" 12 | #include "OrderingMethods" 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | /** \defgroup SparseQR_Module SparseQR module 16 | * \brief Provides QR decomposition for sparse matrices 17 | * 18 | * This module provides a simplicial version of the left-looking Sparse QR decomposition. 19 | * The columns of the input matrix should be reordered to limit the fill-in during the 20 | * decomposition. Built-in methods (COLAMD, AMD) or external methods (METIS) can be used to this end. 21 | * See the \link OrderingMethods_Module OrderingMethods\endlink module for the list 22 | * of built-in and external ordering methods. 23 | * 24 | * \code 25 | * #include 26 | * \endcode 27 | * 28 | * 29 | */ 30 | 31 | #include "OrderingMethods" 32 | #include "src/SparseCore/SparseColEtree.h" 33 | #include "src/SparseQR/SparseQR.h" 34 | 35 | #include "src/Core/util/ReenableStupidWarnings.h" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/Eigen/StdDeque: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // Copyright (C) 2009 Hauke Heibel 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_STDDEQUE_MODULE_H 12 | #define EIGEN_STDDEQUE_MODULE_H 13 | 14 | #include "Core" 15 | #include 16 | 17 | #if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ 18 | 19 | #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) 20 | 21 | #else 22 | 23 | #include "src/StlSupport/StdDeque.h" 24 | 25 | #endif 26 | 27 | #endif // EIGEN_STDDEQUE_MODULE_H 28 | -------------------------------------------------------------------------------- /include/Eigen/StdList: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Hauke Heibel 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_STDLIST_MODULE_H 11 | #define EIGEN_STDLIST_MODULE_H 12 | 13 | #include "Core" 14 | #include 15 | 16 | #if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ 17 | 18 | #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) 19 | 20 | #else 21 | 22 | #include "src/StlSupport/StdList.h" 23 | 24 | #endif 25 | 26 | #endif // EIGEN_STDLIST_MODULE_H 27 | -------------------------------------------------------------------------------- /include/Eigen/StdVector: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // Copyright (C) 2009 Hauke Heibel 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_STDVECTOR_MODULE_H 12 | #define EIGEN_STDVECTOR_MODULE_H 13 | 14 | #include "Core" 15 | #include 16 | 17 | #if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ 18 | 19 | #define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) 20 | 21 | #else 22 | 23 | #include "src/StlSupport/StdVector.h" 24 | 25 | #endif 26 | 27 | #endif // EIGEN_STDVECTOR_MODULE_H 28 | -------------------------------------------------------------------------------- /include/Eigen/SuperLUSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_SUPERLUSUPPORT_MODULE_H 9 | #define EIGEN_SUPERLUSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | #ifdef EMPTY 16 | #define EIGEN_EMPTY_WAS_ALREADY_DEFINED 17 | #endif 18 | 19 | typedef int int_t; 20 | #include 21 | #include 22 | #include 23 | 24 | // slu_util.h defines a preprocessor token named EMPTY which is really polluting, 25 | // so we remove it in favor of a SUPERLU_EMPTY token. 26 | // If EMPTY was already defined then we don't undef it. 27 | 28 | #if defined(EIGEN_EMPTY_WAS_ALREADY_DEFINED) 29 | # undef EIGEN_EMPTY_WAS_ALREADY_DEFINED 30 | #elif defined(EMPTY) 31 | # undef EMPTY 32 | #endif 33 | 34 | #define SUPERLU_EMPTY (-1) 35 | 36 | namespace Eigen { struct SluMatrix; } 37 | 38 | /** \ingroup Support_modules 39 | * \defgroup SuperLUSupport_Module SuperLUSupport module 40 | * 41 | * This module provides an interface to the SuperLU library. 42 | * It provides the following factorization class: 43 | * - class SuperLU: a supernodal sequential LU factorization. 44 | * - class SuperILU: a supernodal sequential incomplete LU factorization (to be used as a preconditioner for iterative methods). 45 | * 46 | * \warning This wrapper requires at least versions 4.0 of SuperLU. The 3.x versions are not supported. 47 | * 48 | * \warning When including this module, you have to use SUPERLU_EMPTY instead of EMPTY which is no longer defined because it is too polluting. 49 | * 50 | * \code 51 | * #include 52 | * \endcode 53 | * 54 | * In order to use this module, the superlu headers must be accessible from the include paths, and your binary must be linked to the superlu library and its dependencies. 55 | * The dependencies depend on how superlu has been compiled. 56 | * For a cmake based project, you can use our FindSuperLU.cmake module to help you in this task. 57 | * 58 | */ 59 | 60 | #include "src/SuperLUSupport/SuperLUSupport.h" 61 | 62 | #include "src/Core/util/ReenableStupidWarnings.h" 63 | 64 | #endif // EIGEN_SUPERLUSUPPORT_MODULE_H 65 | -------------------------------------------------------------------------------- /include/Eigen/UmfPackSupport: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | #ifndef EIGEN_UMFPACKSUPPORT_MODULE_H 9 | #define EIGEN_UMFPACKSUPPORT_MODULE_H 10 | 11 | #include "SparseCore" 12 | 13 | #include "src/Core/util/DisableStupidWarnings.h" 14 | 15 | extern "C" { 16 | #include 17 | } 18 | 19 | /** \ingroup Support_modules 20 | * \defgroup UmfPackSupport_Module UmfPackSupport module 21 | * 22 | * This module provides an interface to the UmfPack library which is part of the suitesparse package. 23 | * It provides the following factorization class: 24 | * - class UmfPackLU: a multifrontal sequential LU factorization. 25 | * 26 | * \code 27 | * #include 28 | * \endcode 29 | * 30 | * In order to use this module, the umfpack headers must be accessible from the include paths, and your binary must be linked to the umfpack library and its dependencies. 31 | * The dependencies depend on how umfpack has been compiled. 32 | * For a cmake based project, you can use our FindUmfPack.cmake module to help you in this task. 33 | * 34 | */ 35 | 36 | #include "src/UmfPackSupport/UmfPackSupport.h" 37 | 38 | #include "src/Core/util/ReenableStupidWarnings.h" 39 | 40 | #endif // EIGEN_UMFPACKSUPPORT_MODULE_H 41 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/Assign.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2007 Michael Olbrich 5 | // Copyright (C) 2006-2010 Benoit Jacob 6 | // Copyright (C) 2008 Gael Guennebaud 7 | // 8 | // This Source Code Form is subject to the terms of the Mozilla 9 | // Public License v. 2.0. If a copy of the MPL was not distributed 10 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 11 | 12 | #ifndef EIGEN_ASSIGN_H 13 | #define EIGEN_ASSIGN_H 14 | 15 | namespace Eigen { 16 | 17 | template 18 | template 19 | EIGEN_STRONG_INLINE Derived& DenseBase 20 | ::lazyAssign(const DenseBase& other) 21 | { 22 | enum{ 23 | SameType = internal::is_same::value 24 | }; 25 | 26 | EIGEN_STATIC_ASSERT_LVALUE(Derived) 27 | EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived) 28 | EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 29 | 30 | eigen_assert(rows() == other.rows() && cols() == other.cols()); 31 | internal::call_assignment_no_alias(derived(),other.derived()); 32 | 33 | return derived(); 34 | } 35 | 36 | template 37 | template 38 | EIGEN_DEVICE_FUNC 39 | EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) 40 | { 41 | internal::call_assignment(derived(), other.derived()); 42 | return derived(); 43 | } 44 | 45 | template 46 | EIGEN_DEVICE_FUNC 47 | EIGEN_STRONG_INLINE Derived& DenseBase::operator=(const DenseBase& other) 48 | { 49 | internal::call_assignment(derived(), other.derived()); 50 | return derived(); 51 | } 52 | 53 | template 54 | EIGEN_DEVICE_FUNC 55 | EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const MatrixBase& other) 56 | { 57 | internal::call_assignment(derived(), other.derived()); 58 | return derived(); 59 | } 60 | 61 | template 62 | template 63 | EIGEN_DEVICE_FUNC 64 | EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const DenseBase& other) 65 | { 66 | internal::call_assignment(derived(), other.derived()); 67 | return derived(); 68 | } 69 | 70 | template 71 | template 72 | EIGEN_DEVICE_FUNC 73 | EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const EigenBase& other) 74 | { 75 | internal::call_assignment(derived(), other.derived()); 76 | return derived(); 77 | } 78 | 79 | template 80 | template 81 | EIGEN_DEVICE_FUNC 82 | EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const ReturnByValue& other) 83 | { 84 | other.derived().evalTo(derived()); 85 | return derived(); 86 | } 87 | 88 | } // end namespace Eigen 89 | 90 | #endif // EIGEN_ASSIGN_H 91 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/DiagonalProduct.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // Copyright (C) 2007-2009 Benoit Jacob 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_DIAGONALPRODUCT_H 12 | #define EIGEN_DIAGONALPRODUCT_H 13 | 14 | namespace Eigen { 15 | 16 | /** \returns the diagonal matrix product of \c *this by the diagonal matrix \a diagonal. 17 | */ 18 | template 19 | template 20 | inline const Product 21 | MatrixBase::operator*(const DiagonalBase &a_diagonal) const 22 | { 23 | return Product(derived(),a_diagonal.derived()); 24 | } 25 | 26 | } // end namespace Eigen 27 | 28 | #endif // EIGEN_DIAGONALPRODUCT_H 29 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/Inverse.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2014 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_INVERSE_H 11 | #define EIGEN_INVERSE_H 12 | 13 | namespace Eigen { 14 | 15 | template class InverseImpl; 16 | 17 | namespace internal { 18 | 19 | template 20 | struct traits > 21 | : traits 22 | { 23 | typedef typename XprType::PlainObject PlainObject; 24 | typedef traits BaseTraits; 25 | enum { 26 | Flags = BaseTraits::Flags & RowMajorBit 27 | }; 28 | }; 29 | 30 | } // end namespace internal 31 | 32 | /** \class Inverse 33 | * 34 | * \brief Expression of the inverse of another expression 35 | * 36 | * \tparam XprType the type of the expression we are taking the inverse 37 | * 38 | * This class represents an abstract expression of A.inverse() 39 | * and most of the time this is the only way it is used. 40 | * 41 | */ 42 | template 43 | class Inverse : public InverseImpl::StorageKind> 44 | { 45 | public: 46 | typedef typename XprType::StorageIndex StorageIndex; 47 | typedef typename XprType::PlainObject PlainObject; 48 | typedef typename XprType::Scalar Scalar; 49 | typedef typename internal::ref_selector::type XprTypeNested; 50 | typedef typename internal::remove_all::type XprTypeNestedCleaned; 51 | typedef typename internal::ref_selector::type Nested; 52 | typedef typename internal::remove_all::type NestedExpression; 53 | 54 | explicit EIGEN_DEVICE_FUNC Inverse(const XprType &xpr) 55 | : m_xpr(xpr) 56 | {} 57 | 58 | EIGEN_DEVICE_FUNC Index rows() const { return m_xpr.rows(); } 59 | EIGEN_DEVICE_FUNC Index cols() const { return m_xpr.cols(); } 60 | 61 | EIGEN_DEVICE_FUNC const XprTypeNestedCleaned& nestedExpression() const { return m_xpr; } 62 | 63 | protected: 64 | XprTypeNested m_xpr; 65 | }; 66 | 67 | // Generic API dispatcher 68 | template 69 | class InverseImpl 70 | : public internal::generic_xpr_base >::type 71 | { 72 | public: 73 | typedef typename internal::generic_xpr_base >::type Base; 74 | typedef typename XprType::Scalar Scalar; 75 | private: 76 | 77 | Scalar coeff(Index row, Index col) const; 78 | Scalar coeff(Index i) const; 79 | }; 80 | 81 | namespace internal { 82 | 83 | /** \internal 84 | * \brief Default evaluator for Inverse expression. 85 | * 86 | * This default evaluator for Inverse expression simply evaluate the inverse into a temporary 87 | * by a call to internal::call_assignment_no_alias. 88 | * Therefore, inverse implementers only have to specialize Assignment, ...> for 89 | * there own nested expression. 90 | * 91 | * \sa class Inverse 92 | */ 93 | template 94 | struct unary_evaluator > 95 | : public evaluator::PlainObject> 96 | { 97 | typedef Inverse InverseType; 98 | typedef typename InverseType::PlainObject PlainObject; 99 | typedef evaluator Base; 100 | 101 | enum { Flags = Base::Flags | EvalBeforeNestingBit }; 102 | 103 | unary_evaluator(const InverseType& inv_xpr) 104 | : m_result(inv_xpr.rows(), inv_xpr.cols()) 105 | { 106 | ::new (static_cast(this)) Base(m_result); 107 | internal::call_assignment_no_alias(m_result, inv_xpr); 108 | } 109 | 110 | protected: 111 | PlainObject m_result; 112 | }; 113 | 114 | } // end namespace internal 115 | 116 | } // end namespace Eigen 117 | 118 | #endif // EIGEN_INVERSE_H 119 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/MathFunctionsImpl.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com) 5 | // Copyright (C) 2016 Gael Guennebaud 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_MATHFUNCTIONSIMPL_H 12 | #define EIGEN_MATHFUNCTIONSIMPL_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | 18 | /** \internal \returns the hyperbolic tan of \a a (coeff-wise) 19 | Doesn't do anything fancy, just a 13/6-degree rational interpolant which 20 | is accurate up to a couple of ulp in the range [-9, 9], outside of which 21 | the tanh(x) = +/-1. 22 | 23 | This implementation works on both scalars and packets. 24 | */ 25 | template 26 | T generic_fast_tanh_float(const T& a_x) 27 | { 28 | // Clamp the inputs to the range [-9, 9] since anything outside 29 | // this range is +/-1.0f in single-precision. 30 | const T plus_9 = pset1(9.f); 31 | const T minus_9 = pset1(-9.f); 32 | // NOTE GCC prior to 6.3 might improperly optimize this max/min 33 | // step such that if a_x is nan, x will be either 9 or -9, 34 | // and tanh will return 1 or -1 instead of nan. 35 | // This is supposed to be fixed in gcc6.3, 36 | // see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72867 37 | const T x = pmax(minus_9,pmin(plus_9,a_x)); 38 | // The monomial coefficients of the numerator polynomial (odd). 39 | const T alpha_1 = pset1(4.89352455891786e-03f); 40 | const T alpha_3 = pset1(6.37261928875436e-04f); 41 | const T alpha_5 = pset1(1.48572235717979e-05f); 42 | const T alpha_7 = pset1(5.12229709037114e-08f); 43 | const T alpha_9 = pset1(-8.60467152213735e-11f); 44 | const T alpha_11 = pset1(2.00018790482477e-13f); 45 | const T alpha_13 = pset1(-2.76076847742355e-16f); 46 | 47 | // The monomial coefficients of the denominator polynomial (even). 48 | const T beta_0 = pset1(4.89352518554385e-03f); 49 | const T beta_2 = pset1(2.26843463243900e-03f); 50 | const T beta_4 = pset1(1.18534705686654e-04f); 51 | const T beta_6 = pset1(1.19825839466702e-06f); 52 | 53 | // Since the polynomials are odd/even, we need x^2. 54 | const T x2 = pmul(x, x); 55 | 56 | // Evaluate the numerator polynomial p. 57 | T p = pmadd(x2, alpha_13, alpha_11); 58 | p = pmadd(x2, p, alpha_9); 59 | p = pmadd(x2, p, alpha_7); 60 | p = pmadd(x2, p, alpha_5); 61 | p = pmadd(x2, p, alpha_3); 62 | p = pmadd(x2, p, alpha_1); 63 | p = pmul(x, p); 64 | 65 | // Evaluate the denominator polynomial p. 66 | T q = pmadd(x2, beta_6, beta_4); 67 | q = pmadd(x2, q, beta_2); 68 | q = pmadd(x2, q, beta_0); 69 | 70 | // Divide the numerator by the denominator. 71 | return pdiv(p, q); 72 | } 73 | 74 | } // end namespace internal 75 | 76 | } // end namespace Eigen 77 | 78 | #endif // EIGEN_MATHFUNCTIONSIMPL_H 79 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/NestByValue.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_NESTBYVALUE_H 12 | #define EIGEN_NESTBYVALUE_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | template 18 | struct traits > : public traits 19 | {}; 20 | } 21 | 22 | /** \class NestByValue 23 | * \ingroup Core_Module 24 | * 25 | * \brief Expression which must be nested by value 26 | * 27 | * \tparam ExpressionType the type of the object of which we are requiring nesting-by-value 28 | * 29 | * This class is the return type of MatrixBase::nestByValue() 30 | * and most of the time this is the only way it is used. 31 | * 32 | * \sa MatrixBase::nestByValue() 33 | */ 34 | template class NestByValue 35 | : public internal::dense_xpr_base< NestByValue >::type 36 | { 37 | public: 38 | 39 | typedef typename internal::dense_xpr_base::type Base; 40 | EIGEN_DENSE_PUBLIC_INTERFACE(NestByValue) 41 | 42 | EIGEN_DEVICE_FUNC explicit inline NestByValue(const ExpressionType& matrix) : m_expression(matrix) {} 43 | 44 | EIGEN_DEVICE_FUNC inline Index rows() const { return m_expression.rows(); } 45 | EIGEN_DEVICE_FUNC inline Index cols() const { return m_expression.cols(); } 46 | EIGEN_DEVICE_FUNC inline Index outerStride() const { return m_expression.outerStride(); } 47 | EIGEN_DEVICE_FUNC inline Index innerStride() const { return m_expression.innerStride(); } 48 | 49 | EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index row, Index col) const 50 | { 51 | return m_expression.coeff(row, col); 52 | } 53 | 54 | EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index row, Index col) 55 | { 56 | return m_expression.const_cast_derived().coeffRef(row, col); 57 | } 58 | 59 | EIGEN_DEVICE_FUNC inline const CoeffReturnType coeff(Index index) const 60 | { 61 | return m_expression.coeff(index); 62 | } 63 | 64 | EIGEN_DEVICE_FUNC inline Scalar& coeffRef(Index index) 65 | { 66 | return m_expression.const_cast_derived().coeffRef(index); 67 | } 68 | 69 | template 70 | inline const PacketScalar packet(Index row, Index col) const 71 | { 72 | return m_expression.template packet(row, col); 73 | } 74 | 75 | template 76 | inline void writePacket(Index row, Index col, const PacketScalar& x) 77 | { 78 | m_expression.const_cast_derived().template writePacket(row, col, x); 79 | } 80 | 81 | template 82 | inline const PacketScalar packet(Index index) const 83 | { 84 | return m_expression.template packet(index); 85 | } 86 | 87 | template 88 | inline void writePacket(Index index, const PacketScalar& x) 89 | { 90 | m_expression.const_cast_derived().template writePacket(index, x); 91 | } 92 | 93 | EIGEN_DEVICE_FUNC operator const ExpressionType&() const { return m_expression; } 94 | 95 | protected: 96 | const ExpressionType m_expression; 97 | }; 98 | 99 | /** \returns an expression of the temporary version of *this. 100 | */ 101 | template 102 | inline const NestByValue 103 | DenseBase::nestByValue() const 104 | { 105 | return NestByValue(derived()); 106 | } 107 | 108 | } // end namespace Eigen 109 | 110 | #endif // EIGEN_NESTBYVALUE_H 111 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/NoAlias.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_NOALIAS_H 11 | #define EIGEN_NOALIAS_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class NoAlias 16 | * \ingroup Core_Module 17 | * 18 | * \brief Pseudo expression providing an operator = assuming no aliasing 19 | * 20 | * \tparam ExpressionType the type of the object on which to do the lazy assignment 21 | * 22 | * This class represents an expression with special assignment operators 23 | * assuming no aliasing between the target expression and the source expression. 24 | * More precisely it alloas to bypass the EvalBeforeAssignBit flag of the source expression. 25 | * It is the return type of MatrixBase::noalias() 26 | * and most of the time this is the only way it is used. 27 | * 28 | * \sa MatrixBase::noalias() 29 | */ 30 | template class StorageBase> 31 | class NoAlias 32 | { 33 | public: 34 | typedef typename ExpressionType::Scalar Scalar; 35 | 36 | explicit NoAlias(ExpressionType& expression) : m_expression(expression) {} 37 | 38 | template 39 | EIGEN_DEVICE_FUNC 40 | EIGEN_STRONG_INLINE ExpressionType& operator=(const StorageBase& other) 41 | { 42 | call_assignment_no_alias(m_expression, other.derived(), internal::assign_op()); 43 | return m_expression; 44 | } 45 | 46 | template 47 | EIGEN_DEVICE_FUNC 48 | EIGEN_STRONG_INLINE ExpressionType& operator+=(const StorageBase& other) 49 | { 50 | call_assignment_no_alias(m_expression, other.derived(), internal::add_assign_op()); 51 | return m_expression; 52 | } 53 | 54 | template 55 | EIGEN_DEVICE_FUNC 56 | EIGEN_STRONG_INLINE ExpressionType& operator-=(const StorageBase& other) 57 | { 58 | call_assignment_no_alias(m_expression, other.derived(), internal::sub_assign_op()); 59 | return m_expression; 60 | } 61 | 62 | EIGEN_DEVICE_FUNC 63 | ExpressionType& expression() const 64 | { 65 | return m_expression; 66 | } 67 | 68 | protected: 69 | ExpressionType& m_expression; 70 | }; 71 | 72 | /** \returns a pseudo expression of \c *this with an operator= assuming 73 | * no aliasing between \c *this and the source expression. 74 | * 75 | * More precisely, noalias() allows to bypass the EvalBeforeAssignBit flag. 76 | * Currently, even though several expressions may alias, only product 77 | * expressions have this flag. Therefore, noalias() is only usefull when 78 | * the source expression contains a matrix product. 79 | * 80 | * Here are some examples where noalias is usefull: 81 | * \code 82 | * D.noalias() = A * B; 83 | * D.noalias() += A.transpose() * B; 84 | * D.noalias() -= 2 * A * B.adjoint(); 85 | * \endcode 86 | * 87 | * On the other hand the following example will lead to a \b wrong result: 88 | * \code 89 | * A.noalias() = A * B; 90 | * \endcode 91 | * because the result matrix A is also an operand of the matrix product. Therefore, 92 | * there is no alternative than evaluating A * B in a temporary, that is the default 93 | * behavior when you write: 94 | * \code 95 | * A = A * B; 96 | * \endcode 97 | * 98 | * \sa class NoAlias 99 | */ 100 | template 101 | NoAlias MatrixBase::noalias() 102 | { 103 | return NoAlias(derived()); 104 | } 105 | 106 | } // end namespace Eigen 107 | 108 | #endif // EIGEN_NOALIAS_H 109 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/SelfCwiseBinaryOp.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009-2010 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SELFCWISEBINARYOP_H 11 | #define EIGEN_SELFCWISEBINARYOP_H 12 | 13 | namespace Eigen { 14 | 15 | // TODO generalize the scalar type of 'other' 16 | 17 | template 18 | EIGEN_STRONG_INLINE Derived& DenseBase::operator*=(const Scalar& other) 19 | { 20 | typedef typename Derived::PlainObject PlainObject; 21 | internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::mul_assign_op()); 22 | return derived(); 23 | } 24 | 25 | template 26 | EIGEN_STRONG_INLINE Derived& ArrayBase::operator+=(const Scalar& other) 27 | { 28 | typedef typename Derived::PlainObject PlainObject; 29 | internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::add_assign_op()); 30 | return derived(); 31 | } 32 | 33 | template 34 | EIGEN_STRONG_INLINE Derived& ArrayBase::operator-=(const Scalar& other) 35 | { 36 | typedef typename Derived::PlainObject PlainObject; 37 | internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::sub_assign_op()); 38 | return derived(); 39 | } 40 | 41 | template 42 | EIGEN_STRONG_INLINE Derived& DenseBase::operator/=(const Scalar& other) 43 | { 44 | typedef typename Derived::PlainObject PlainObject; 45 | internal::call_assignment(this->derived(), PlainObject::Constant(rows(),cols(),other), internal::div_assign_op()); 46 | return derived(); 47 | } 48 | 49 | } // end namespace Eigen 50 | 51 | #endif // EIGEN_SELFCWISEBINARYOP_H 52 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/Swap.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2006-2008 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SWAP_H 11 | #define EIGEN_SWAP_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | // Overload default assignPacket behavior for swapping them 18 | template 19 | class generic_dense_assignment_kernel, Specialized> 20 | : public generic_dense_assignment_kernel, BuiltIn> 21 | { 22 | protected: 23 | typedef generic_dense_assignment_kernel, BuiltIn> Base; 24 | using Base::m_dst; 25 | using Base::m_src; 26 | using Base::m_functor; 27 | 28 | public: 29 | typedef typename Base::Scalar Scalar; 30 | typedef typename Base::DstXprType DstXprType; 31 | typedef swap_assign_op Functor; 32 | 33 | EIGEN_DEVICE_FUNC generic_dense_assignment_kernel(DstEvaluatorTypeT &dst, const SrcEvaluatorTypeT &src, const Functor &func, DstXprType& dstExpr) 34 | : Base(dst, src, func, dstExpr) 35 | {} 36 | 37 | template 38 | void assignPacket(Index row, Index col) 39 | { 40 | PacketType tmp = m_src.template packet(row,col); 41 | const_cast(m_src).template writePacket(row,col, m_dst.template packet(row,col)); 42 | m_dst.template writePacket(row,col,tmp); 43 | } 44 | 45 | template 46 | void assignPacket(Index index) 47 | { 48 | PacketType tmp = m_src.template packet(index); 49 | const_cast(m_src).template writePacket(index, m_dst.template packet(index)); 50 | m_dst.template writePacket(index,tmp); 51 | } 52 | 53 | // TODO find a simple way not to have to copy/paste this function from generic_dense_assignment_kernel, by simple I mean no CRTP (Gael) 54 | template 55 | void assignPacketByOuterInner(Index outer, Index inner) 56 | { 57 | Index row = Base::rowIndexByOuterInner(outer, inner); 58 | Index col = Base::colIndexByOuterInner(outer, inner); 59 | assignPacket(row, col); 60 | } 61 | }; 62 | 63 | } // namespace internal 64 | 65 | } // end namespace Eigen 66 | 67 | #endif // EIGEN_SWAP_H 68 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/VectorBlock.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_VECTORBLOCK_H 12 | #define EIGEN_VECTORBLOCK_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | template 18 | struct traits > 19 | : public traits::Flags & RowMajorBit ? 1 : Size, 21 | traits::Flags & RowMajorBit ? Size : 1> > 22 | { 23 | }; 24 | } 25 | 26 | /** \class VectorBlock 27 | * \ingroup Core_Module 28 | * 29 | * \brief Expression of a fixed-size or dynamic-size sub-vector 30 | * 31 | * \tparam VectorType the type of the object in which we are taking a sub-vector 32 | * \tparam Size size of the sub-vector we are taking at compile time (optional) 33 | * 34 | * This class represents an expression of either a fixed-size or dynamic-size sub-vector. 35 | * It is the return type of DenseBase::segment(Index,Index) and DenseBase::segment(Index) and 36 | * most of the time this is the only way it is used. 37 | * 38 | * However, if you want to directly maniputate sub-vector expressions, 39 | * for instance if you want to write a function returning such an expression, you 40 | * will need to use this class. 41 | * 42 | * Here is an example illustrating the dynamic case: 43 | * \include class_VectorBlock.cpp 44 | * Output: \verbinclude class_VectorBlock.out 45 | * 46 | * \note Even though this expression has dynamic size, in the case where \a VectorType 47 | * has fixed size, this expression inherits a fixed maximal size which means that evaluating 48 | * it does not cause a dynamic memory allocation. 49 | * 50 | * Here is an example illustrating the fixed-size case: 51 | * \include class_FixedVectorBlock.cpp 52 | * Output: \verbinclude class_FixedVectorBlock.out 53 | * 54 | * \sa class Block, DenseBase::segment(Index,Index,Index,Index), DenseBase::segment(Index,Index) 55 | */ 56 | template class VectorBlock 57 | : public Block::Flags & RowMajorBit ? 1 : Size, 59 | internal::traits::Flags & RowMajorBit ? Size : 1> 60 | { 61 | typedef Block::Flags & RowMajorBit ? 1 : Size, 63 | internal::traits::Flags & RowMajorBit ? Size : 1> Base; 64 | enum { 65 | IsColVector = !(internal::traits::Flags & RowMajorBit) 66 | }; 67 | public: 68 | EIGEN_DENSE_PUBLIC_INTERFACE(VectorBlock) 69 | 70 | using Base::operator=; 71 | 72 | /** Dynamic-size constructor 73 | */ 74 | EIGEN_DEVICE_FUNC 75 | inline VectorBlock(VectorType& vector, Index start, Index size) 76 | : Base(vector, 77 | IsColVector ? start : 0, IsColVector ? 0 : start, 78 | IsColVector ? size : 1, IsColVector ? 1 : size) 79 | { 80 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); 81 | } 82 | 83 | /** Fixed-size constructor 84 | */ 85 | EIGEN_DEVICE_FUNC 86 | inline VectorBlock(VectorType& vector, Index start) 87 | : Base(vector, IsColVector ? start : 0, IsColVector ? 0 : start) 88 | { 89 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorBlock); 90 | } 91 | }; 92 | 93 | 94 | } // end namespace Eigen 95 | 96 | #endif // EIGEN_VECTORBLOCK_H 97 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/arch/AVX/TypeCasting.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2015 Benoit Steiner 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_TYPE_CASTING_AVX_H 11 | #define EIGEN_TYPE_CASTING_AVX_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | // For now we use SSE to handle integers, so we can't use AVX instructions to cast 18 | // from int to float 19 | template <> 20 | struct type_casting_traits { 21 | enum { 22 | VectorizedCast = 0, 23 | SrcCoeffRatio = 1, 24 | TgtCoeffRatio = 1 25 | }; 26 | }; 27 | 28 | template <> 29 | struct type_casting_traits { 30 | enum { 31 | VectorizedCast = 0, 32 | SrcCoeffRatio = 1, 33 | TgtCoeffRatio = 1 34 | }; 35 | }; 36 | 37 | 38 | 39 | template<> EIGEN_STRONG_INLINE Packet8i pcast(const Packet8f& a) { 40 | return _mm256_cvtps_epi32(a); 41 | } 42 | 43 | template<> EIGEN_STRONG_INLINE Packet8f pcast(const Packet8i& a) { 44 | return _mm256_cvtepi32_ps(a); 45 | } 46 | 47 | } // end namespace internal 48 | 49 | } // end namespace Eigen 50 | 51 | #endif // EIGEN_TYPE_CASTING_AVX_H 52 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/arch/CUDA/MathFunctions.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2014 Benoit Steiner 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MATH_FUNCTIONS_CUDA_H 11 | #define EIGEN_MATH_FUNCTIONS_CUDA_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | // Make sure this is only available when targeting a GPU: we don't want to 18 | // introduce conflicts between these packet_traits definitions and the ones 19 | // we'll use on the host side (SSE, AVX, ...) 20 | #if defined(__CUDACC__) && defined(EIGEN_USE_GPU) 21 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 22 | float4 plog(const float4& a) 23 | { 24 | return make_float4(logf(a.x), logf(a.y), logf(a.z), logf(a.w)); 25 | } 26 | 27 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 28 | double2 plog(const double2& a) 29 | { 30 | using ::log; 31 | return make_double2(log(a.x), log(a.y)); 32 | } 33 | 34 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 35 | float4 plog1p(const float4& a) 36 | { 37 | return make_float4(log1pf(a.x), log1pf(a.y), log1pf(a.z), log1pf(a.w)); 38 | } 39 | 40 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 41 | double2 plog1p(const double2& a) 42 | { 43 | return make_double2(log1p(a.x), log1p(a.y)); 44 | } 45 | 46 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 47 | float4 pexp(const float4& a) 48 | { 49 | return make_float4(expf(a.x), expf(a.y), expf(a.z), expf(a.w)); 50 | } 51 | 52 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 53 | double2 pexp(const double2& a) 54 | { 55 | using ::exp; 56 | return make_double2(exp(a.x), exp(a.y)); 57 | } 58 | 59 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 60 | float4 psqrt(const float4& a) 61 | { 62 | return make_float4(sqrtf(a.x), sqrtf(a.y), sqrtf(a.z), sqrtf(a.w)); 63 | } 64 | 65 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 66 | double2 psqrt(const double2& a) 67 | { 68 | using ::sqrt; 69 | return make_double2(sqrt(a.x), sqrt(a.y)); 70 | } 71 | 72 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 73 | float4 prsqrt(const float4& a) 74 | { 75 | return make_float4(rsqrtf(a.x), rsqrtf(a.y), rsqrtf(a.z), rsqrtf(a.w)); 76 | } 77 | 78 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 79 | double2 prsqrt(const double2& a) 80 | { 81 | return make_double2(rsqrt(a.x), rsqrt(a.y)); 82 | } 83 | 84 | 85 | #endif 86 | 87 | } // end namespace internal 88 | 89 | } // end namespace Eigen 90 | 91 | #endif // EIGEN_MATH_FUNCTIONS_CUDA_H 92 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/arch/Default/Settings.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2010 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | 12 | /* All the parameters defined in this file can be specialized in the 13 | * architecture specific files, and/or by the user. 14 | * More to come... */ 15 | 16 | #ifndef EIGEN_DEFAULT_SETTINGS_H 17 | #define EIGEN_DEFAULT_SETTINGS_H 18 | 19 | /** Defines the maximal loop size to enable meta unrolling of loops. 20 | * Note that the value here is expressed in Eigen's own notion of "number of FLOPS", 21 | * it does not correspond to the number of iterations or the number of instructions 22 | */ 23 | #ifndef EIGEN_UNROLLING_LIMIT 24 | #define EIGEN_UNROLLING_LIMIT 100 25 | #endif 26 | 27 | /** Defines the threshold between a "small" and a "large" matrix. 28 | * This threshold is mainly used to select the proper product implementation. 29 | */ 30 | #ifndef EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 31 | #define EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD 8 32 | #endif 33 | 34 | /** Defines the maximal width of the blocks used in the triangular product and solver 35 | * for vectors (level 2 blas xTRMV and xTRSV). The default is 8. 36 | */ 37 | #ifndef EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 38 | #define EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH 8 39 | #endif 40 | 41 | 42 | /** Defines the default number of registers available for that architecture. 43 | * Currently it must be 8 or 16. Other values will fail. 44 | */ 45 | #ifndef EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 46 | #define EIGEN_ARCH_DEFAULT_NUMBER_OF_REGISTERS 8 47 | #endif 48 | 49 | #endif // EIGEN_DEFAULT_SETTINGS_H 50 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/arch/NEON/MathFunctions.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // This Source Code Form is subject to the terms of the Mozilla 5 | // Public License v. 2.0. If a copy of the MPL was not distributed 6 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | /* The sin, cos, exp, and log functions of this file come from 9 | * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ 10 | */ 11 | 12 | #ifndef EIGEN_MATH_FUNCTIONS_NEON_H 13 | #define EIGEN_MATH_FUNCTIONS_NEON_H 14 | 15 | namespace Eigen { 16 | 17 | namespace internal { 18 | 19 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 20 | Packet4f pexp(const Packet4f& _x) 21 | { 22 | Packet4f x = _x; 23 | Packet4f tmp, fx; 24 | 25 | _EIGEN_DECLARE_CONST_Packet4f(1 , 1.0f); 26 | _EIGEN_DECLARE_CONST_Packet4f(half, 0.5f); 27 | _EIGEN_DECLARE_CONST_Packet4i(0x7f, 0x7f); 28 | _EIGEN_DECLARE_CONST_Packet4f(exp_hi, 88.3762626647950f); 29 | _EIGEN_DECLARE_CONST_Packet4f(exp_lo, -88.3762626647949f); 30 | _EIGEN_DECLARE_CONST_Packet4f(cephes_LOG2EF, 1.44269504088896341f); 31 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C1, 0.693359375f); 32 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_C2, -2.12194440e-4f); 33 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p0, 1.9875691500E-4f); 34 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p1, 1.3981999507E-3f); 35 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p2, 8.3334519073E-3f); 36 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p3, 4.1665795894E-2f); 37 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p4, 1.6666665459E-1f); 38 | _EIGEN_DECLARE_CONST_Packet4f(cephes_exp_p5, 5.0000001201E-1f); 39 | 40 | x = vminq_f32(x, p4f_exp_hi); 41 | x = vmaxq_f32(x, p4f_exp_lo); 42 | 43 | /* express exp(x) as exp(g + n*log(2)) */ 44 | fx = vmlaq_f32(p4f_half, x, p4f_cephes_LOG2EF); 45 | 46 | /* perform a floorf */ 47 | tmp = vcvtq_f32_s32(vcvtq_s32_f32(fx)); 48 | 49 | /* if greater, substract 1 */ 50 | Packet4ui mask = vcgtq_f32(tmp, fx); 51 | mask = vandq_u32(mask, vreinterpretq_u32_f32(p4f_1)); 52 | 53 | fx = vsubq_f32(tmp, vreinterpretq_f32_u32(mask)); 54 | 55 | tmp = vmulq_f32(fx, p4f_cephes_exp_C1); 56 | Packet4f z = vmulq_f32(fx, p4f_cephes_exp_C2); 57 | x = vsubq_f32(x, tmp); 58 | x = vsubq_f32(x, z); 59 | 60 | Packet4f y = vmulq_f32(p4f_cephes_exp_p0, x); 61 | z = vmulq_f32(x, x); 62 | y = vaddq_f32(y, p4f_cephes_exp_p1); 63 | y = vmulq_f32(y, x); 64 | y = vaddq_f32(y, p4f_cephes_exp_p2); 65 | y = vmulq_f32(y, x); 66 | y = vaddq_f32(y, p4f_cephes_exp_p3); 67 | y = vmulq_f32(y, x); 68 | y = vaddq_f32(y, p4f_cephes_exp_p4); 69 | y = vmulq_f32(y, x); 70 | y = vaddq_f32(y, p4f_cephes_exp_p5); 71 | 72 | y = vmulq_f32(y, z); 73 | y = vaddq_f32(y, x); 74 | y = vaddq_f32(y, p4f_1); 75 | 76 | /* build 2^n */ 77 | int32x4_t mm; 78 | mm = vcvtq_s32_f32(fx); 79 | mm = vaddq_s32(mm, p4i_0x7f); 80 | mm = vshlq_n_s32(mm, 23); 81 | Packet4f pow2n = vreinterpretq_f32_s32(mm); 82 | 83 | y = vmulq_f32(y, pow2n); 84 | return y; 85 | } 86 | 87 | } // end namespace internal 88 | 89 | } // end namespace Eigen 90 | 91 | #endif // EIGEN_MATH_FUNCTIONS_NEON_H 92 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/arch/SSE/TypeCasting.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2015 Benoit Steiner 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_TYPE_CASTING_SSE_H 11 | #define EIGEN_TYPE_CASTING_SSE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template <> 18 | struct type_casting_traits { 19 | enum { 20 | VectorizedCast = 1, 21 | SrcCoeffRatio = 1, 22 | TgtCoeffRatio = 1 23 | }; 24 | }; 25 | 26 | template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4f& a) { 27 | return _mm_cvttps_epi32(a); 28 | } 29 | 30 | 31 | template <> 32 | struct type_casting_traits { 33 | enum { 34 | VectorizedCast = 1, 35 | SrcCoeffRatio = 1, 36 | TgtCoeffRatio = 1 37 | }; 38 | }; 39 | 40 | template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4i& a) { 41 | return _mm_cvtepi32_ps(a); 42 | } 43 | 44 | 45 | template <> 46 | struct type_casting_traits { 47 | enum { 48 | VectorizedCast = 1, 49 | SrcCoeffRatio = 2, 50 | TgtCoeffRatio = 1 51 | }; 52 | }; 53 | 54 | template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet2d& a, const Packet2d& b) { 55 | return _mm_shuffle_ps(_mm_cvtpd_ps(a), _mm_cvtpd_ps(b), (1 << 2) | (1 << 6)); 56 | } 57 | 58 | template <> 59 | struct type_casting_traits { 60 | enum { 61 | VectorizedCast = 1, 62 | SrcCoeffRatio = 1, 63 | TgtCoeffRatio = 2 64 | }; 65 | }; 66 | 67 | template<> EIGEN_STRONG_INLINE Packet2d pcast(const Packet4f& a) { 68 | // Simply discard the second half of the input 69 | return _mm_cvtps_pd(a); 70 | } 71 | 72 | 73 | } // end namespace internal 74 | 75 | } // end namespace Eigen 76 | 77 | #endif // EIGEN_TYPE_CASTING_SSE_H 78 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/functors/TernaryFunctors.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2016 Eugene Brevdo 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_TERNARY_FUNCTORS_H 11 | #define EIGEN_TERNARY_FUNCTORS_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | //---------- associative ternary functors ---------- 18 | 19 | 20 | 21 | } // end namespace internal 22 | 23 | } // end namespace Eigen 24 | 25 | #endif // EIGEN_TERNARY_FUNCTORS_H 26 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/util/DisableStupidWarnings.h: -------------------------------------------------------------------------------- 1 | #ifndef EIGEN_WARNINGS_DISABLED 2 | #define EIGEN_WARNINGS_DISABLED 3 | 4 | #ifdef _MSC_VER 5 | // 4100 - unreferenced formal parameter (occurred e.g. in aligned_allocator::destroy(pointer p)) 6 | // 4101 - unreferenced local variable 7 | // 4127 - conditional expression is constant 8 | // 4181 - qualifier applied to reference type ignored 9 | // 4211 - nonstandard extension used : redefined extern to static 10 | // 4244 - 'argument' : conversion from 'type1' to 'type2', possible loss of data 11 | // 4273 - QtAlignedMalloc, inconsistent DLL linkage 12 | // 4324 - structure was padded due to declspec(align()) 13 | // 4503 - decorated name length exceeded, name was truncated 14 | // 4512 - assignment operator could not be generated 15 | // 4522 - 'class' : multiple assignment operators specified 16 | // 4700 - uninitialized local variable 'xyz' used 17 | // 4714 - function marked as __forceinline not inlined 18 | // 4717 - 'function' : recursive on all control paths, function will cause runtime stack overflow 19 | // 4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning) 20 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 21 | #pragma warning( push ) 22 | #endif 23 | #pragma warning( disable : 4100 4101 4127 4181 4211 4244 4273 4324 4503 4512 4522 4700 4714 4717 4800) 24 | 25 | #elif defined __INTEL_COMPILER 26 | // 2196 - routine is both "inline" and "noinline" ("noinline" assumed) 27 | // ICC 12 generates this warning even without any inline keyword, when defining class methods 'inline' i.e. inside of class body 28 | // typedef that may be a reference type. 29 | // 279 - controlling expression is constant 30 | // ICC 12 generates this warning on assert(constant_expression_depending_on_template_params) and frankly this is a legitimate use case. 31 | // 1684 - conversion from pointer to same-sized integral type (potential portability problem) 32 | // 2259 - non-pointer conversion from "Eigen::Index={ptrdiff_t={long}}" to "int" may lose significant bits 33 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 34 | #pragma warning push 35 | #endif 36 | #pragma warning disable 2196 279 1684 2259 37 | 38 | #elif defined __clang__ 39 | // -Wconstant-logical-operand - warning: use of logical && with constant operand; switch to bitwise & or remove constant 40 | // this is really a stupid warning as it warns on compile-time expressions involving enums 41 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 42 | #pragma clang diagnostic push 43 | #endif 44 | #pragma clang diagnostic ignored "-Wconstant-logical-operand" 45 | 46 | #elif defined __GNUC__ && __GNUC__>=6 47 | 48 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 49 | #pragma GCC diagnostic push 50 | #endif 51 | #pragma GCC diagnostic ignored "-Wignored-attributes" 52 | 53 | #endif 54 | 55 | #if defined __NVCC__ 56 | // Disable the "statement is unreachable" message 57 | #pragma diag_suppress code_is_unreachable 58 | // Disable the "dynamic initialization in unreachable code" message 59 | #pragma diag_suppress initialization_not_reachable 60 | // Disable the "invalid error number" message that we get with older versions of nvcc 61 | #pragma diag_suppress 1222 62 | // Disable the "calling a __host__ function from a __host__ __device__ function is not allowed" messages (yes, there are many of them and they seem to change with every version of the compiler) 63 | #pragma diag_suppress 2527 64 | #pragma diag_suppress 2529 65 | #pragma diag_suppress 2651 66 | #pragma diag_suppress 2653 67 | #pragma diag_suppress 2668 68 | #pragma diag_suppress 2669 69 | #pragma diag_suppress 2670 70 | #pragma diag_suppress 2671 71 | #pragma diag_suppress 2735 72 | #pragma diag_suppress 2737 73 | #endif 74 | 75 | #endif // not EIGEN_WARNINGS_DISABLED 76 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/util/NonMPL2.h: -------------------------------------------------------------------------------- 1 | #ifdef EIGEN_MPL2_ONLY 2 | #error Including non-MPL2 code in EIGEN_MPL2_ONLY mode 3 | #endif 4 | -------------------------------------------------------------------------------- /include/Eigen/src/Core/util/ReenableStupidWarnings.h: -------------------------------------------------------------------------------- 1 | #ifdef EIGEN_WARNINGS_DISABLED 2 | #undef EIGEN_WARNINGS_DISABLED 3 | 4 | #ifndef EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS 5 | #ifdef _MSC_VER 6 | #pragma warning( pop ) 7 | #elif defined __INTEL_COMPILER 8 | #pragma warning pop 9 | #elif defined __clang__ 10 | #pragma clang diagnostic pop 11 | #elif defined __GNUC__ && __GNUC__>=6 12 | #pragma GCC diagnostic pop 13 | #endif 14 | 15 | #if defined __NVCC__ 16 | // Don't reenable the diagnostic messages, as it turns out these messages need 17 | // to be disabled at the point of the template instantiation (i.e the user code) 18 | // otherwise they'll be triggered by nvcc. 19 | // #pragma diag_default code_is_unreachable 20 | // #pragma diag_default initialization_not_reachable 21 | // #pragma diag_default 2651 22 | // #pragma diag_default 2653 23 | #endif 24 | 25 | #endif 26 | 27 | #endif // EIGEN_WARNINGS_DISABLED 28 | -------------------------------------------------------------------------------- /include/Eigen/src/Eigenvalues/RealSchur_LAPACKE.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to LAPACKe 29 | * Real Schur needed to real unsymmetrical eigenvalues/eigenvectors. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_REAL_SCHUR_LAPACKE_H 34 | #define EIGEN_REAL_SCHUR_LAPACKE_H 35 | 36 | namespace Eigen { 37 | 38 | /** \internal Specialization for the data types supported by LAPACKe */ 39 | 40 | #define EIGEN_LAPACKE_SCHUR_REAL(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX, LAPACKE_PREFIX_U, EIGCOLROW, LAPACKE_COLROW) \ 41 | template<> template inline \ 42 | RealSchur >& \ 43 | RealSchur >::compute(const EigenBase& matrix, bool computeU) \ 44 | { \ 45 | eigen_assert(matrix.cols() == matrix.rows()); \ 46 | \ 47 | lapack_int n = internal::convert_index(matrix.cols()), sdim, info; \ 48 | lapack_int matrix_order = LAPACKE_COLROW; \ 49 | char jobvs, sort='N'; \ 50 | LAPACK_##LAPACKE_PREFIX_U##_SELECT2 select = 0; \ 51 | jobvs = (computeU) ? 'V' : 'N'; \ 52 | m_matU.resize(n, n); \ 53 | lapack_int ldvs = internal::convert_index(m_matU.outerStride()); \ 54 | m_matT = matrix; \ 55 | lapack_int lda = internal::convert_index(m_matT.outerStride()); \ 56 | Matrix wr, wi; \ 57 | wr.resize(n, 1); wi.resize(n, 1); \ 58 | info = LAPACKE_##LAPACKE_PREFIX##gees( matrix_order, jobvs, sort, select, n, (LAPACKE_TYPE*)m_matT.data(), lda, &sdim, (LAPACKE_TYPE*)wr.data(), (LAPACKE_TYPE*)wi.data(), (LAPACKE_TYPE*)m_matU.data(), ldvs ); \ 59 | if(info == 0) \ 60 | m_info = Success; \ 61 | else \ 62 | m_info = NoConvergence; \ 63 | \ 64 | m_isInitialized = true; \ 65 | m_matUisUptodate = computeU; \ 66 | return *this; \ 67 | \ 68 | } 69 | 70 | EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, ColMajor, LAPACK_COL_MAJOR) 71 | EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, ColMajor, LAPACK_COL_MAJOR) 72 | EIGEN_LAPACKE_SCHUR_REAL(double, double, d, D, RowMajor, LAPACK_ROW_MAJOR) 73 | EIGEN_LAPACKE_SCHUR_REAL(float, float, s, S, RowMajor, LAPACK_ROW_MAJOR) 74 | 75 | } // end namespace Eigen 76 | 77 | #endif // EIGEN_REAL_SCHUR_LAPACKE_H 78 | -------------------------------------------------------------------------------- /include/Eigen/src/LU/Determinant.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_DETERMINANT_H 11 | #define EIGEN_DETERMINANT_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | inline const typename Derived::Scalar bruteforce_det3_helper 19 | (const MatrixBase& matrix, int a, int b, int c) 20 | { 21 | return matrix.coeff(0,a) 22 | * (matrix.coeff(1,b) * matrix.coeff(2,c) - matrix.coeff(1,c) * matrix.coeff(2,b)); 23 | } 24 | 25 | template 26 | const typename Derived::Scalar bruteforce_det4_helper 27 | (const MatrixBase& matrix, int j, int k, int m, int n) 28 | { 29 | return (matrix.coeff(j,0) * matrix.coeff(k,1) - matrix.coeff(k,0) * matrix.coeff(j,1)) 30 | * (matrix.coeff(m,2) * matrix.coeff(n,3) - matrix.coeff(n,2) * matrix.coeff(m,3)); 31 | } 32 | 33 | template struct determinant_impl 36 | { 37 | static inline typename traits::Scalar run(const Derived& m) 38 | { 39 | if(Derived::ColsAtCompileTime==Dynamic && m.rows()==0) 40 | return typename traits::Scalar(1); 41 | return m.partialPivLu().determinant(); 42 | } 43 | }; 44 | 45 | template struct determinant_impl 46 | { 47 | static inline typename traits::Scalar run(const Derived& m) 48 | { 49 | return m.coeff(0,0); 50 | } 51 | }; 52 | 53 | template struct determinant_impl 54 | { 55 | static inline typename traits::Scalar run(const Derived& m) 56 | { 57 | return m.coeff(0,0) * m.coeff(1,1) - m.coeff(1,0) * m.coeff(0,1); 58 | } 59 | }; 60 | 61 | template struct determinant_impl 62 | { 63 | static inline typename traits::Scalar run(const Derived& m) 64 | { 65 | return bruteforce_det3_helper(m,0,1,2) 66 | - bruteforce_det3_helper(m,1,0,2) 67 | + bruteforce_det3_helper(m,2,0,1); 68 | } 69 | }; 70 | 71 | template struct determinant_impl 72 | { 73 | static typename traits::Scalar run(const Derived& m) 74 | { 75 | // trick by Martin Costabel to compute 4x4 det with only 30 muls 76 | return bruteforce_det4_helper(m,0,1,2,3) 77 | - bruteforce_det4_helper(m,0,2,1,3) 78 | + bruteforce_det4_helper(m,0,3,1,2) 79 | + bruteforce_det4_helper(m,1,2,0,3) 80 | - bruteforce_det4_helper(m,1,3,0,2) 81 | + bruteforce_det4_helper(m,2,3,0,1); 82 | } 83 | }; 84 | 85 | } // end namespace internal 86 | 87 | /** \lu_module 88 | * 89 | * \returns the determinant of this matrix 90 | */ 91 | template 92 | inline typename internal::traits::Scalar MatrixBase::determinant() const 93 | { 94 | eigen_assert(rows() == cols()); 95 | typedef typename internal::nested_eval::type Nested; 96 | return internal::determinant_impl::type>::run(derived()); 97 | } 98 | 99 | } // end namespace Eigen 100 | 101 | #endif // EIGEN_DETERMINANT_H 102 | -------------------------------------------------------------------------------- /include/Eigen/src/LU/PartialPivLU_LAPACKE.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to LAPACKe 29 | * LU decomposition with partial pivoting based on LAPACKE_?getrf function. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_PARTIALLU_LAPACK_H 34 | #define EIGEN_PARTIALLU_LAPACK_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /** \internal Specialization for the data types supported by LAPACKe */ 41 | 42 | #define EIGEN_LAPACKE_LU_PARTPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \ 43 | template \ 44 | struct partial_lu_impl \ 45 | { \ 46 | /* \internal performs the LU decomposition in-place of the matrix represented */ \ 47 | static lapack_int blocked_lu(Index rows, Index cols, EIGTYPE* lu_data, Index luStride, lapack_int* row_transpositions, lapack_int& nb_transpositions, lapack_int maxBlockSize=256) \ 48 | { \ 49 | EIGEN_UNUSED_VARIABLE(maxBlockSize);\ 50 | lapack_int matrix_order, first_zero_pivot; \ 51 | lapack_int m, n, lda, *ipiv, info; \ 52 | EIGTYPE* a; \ 53 | /* Set up parameters for ?getrf */ \ 54 | matrix_order = StorageOrder==RowMajor ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 55 | lda = convert_index(luStride); \ 56 | a = lu_data; \ 57 | ipiv = row_transpositions; \ 58 | m = convert_index(rows); \ 59 | n = convert_index(cols); \ 60 | nb_transpositions = 0; \ 61 | \ 62 | info = LAPACKE_##LAPACKE_PREFIX##getrf( matrix_order, m, n, (LAPACKE_TYPE*)a, lda, ipiv ); \ 63 | \ 64 | for(int i=0;i= 0); \ 67 | /* something should be done with nb_transpositions */ \ 68 | \ 69 | first_zero_pivot = info; \ 70 | return first_zero_pivot; \ 71 | } \ 72 | }; 73 | 74 | EIGEN_LAPACKE_LU_PARTPIV(double, double, d) 75 | EIGEN_LAPACKE_LU_PARTPIV(float, float, s) 76 | EIGEN_LAPACKE_LU_PARTPIV(dcomplex, lapack_complex_double, z) 77 | EIGEN_LAPACKE_LU_PARTPIV(scomplex, lapack_complex_float, c) 78 | 79 | } // end namespace internal 80 | 81 | } // end namespace Eigen 82 | 83 | #endif // EIGEN_PARTIALLU_LAPACK_H 84 | -------------------------------------------------------------------------------- /include/Eigen/src/QR/HouseholderQR_LAPACKE.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, Intel Corporation. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of Intel Corporation nor the names of its contributors may 13 | be used to endorse or promote products derived from this software without 14 | specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ******************************************************************************** 28 | * Content : Eigen bindings to LAPACKe 29 | * Householder QR decomposition of a matrix w/o pivoting based on 30 | * LAPACKE_?geqrf function. 31 | ******************************************************************************** 32 | */ 33 | 34 | #ifndef EIGEN_QR_LAPACKE_H 35 | #define EIGEN_QR_LAPACKE_H 36 | 37 | namespace Eigen { 38 | 39 | namespace internal { 40 | 41 | /** \internal Specialization for the data types supported by LAPACKe */ 42 | 43 | #define EIGEN_LAPACKE_QR_NOPIV(EIGTYPE, LAPACKE_TYPE, LAPACKE_PREFIX) \ 44 | template \ 45 | struct householder_qr_inplace_blocked \ 46 | { \ 47 | static void run(MatrixQR& mat, HCoeffs& hCoeffs, Index = 32, \ 48 | typename MatrixQR::Scalar* = 0) \ 49 | { \ 50 | lapack_int m = (lapack_int) mat.rows(); \ 51 | lapack_int n = (lapack_int) mat.cols(); \ 52 | lapack_int lda = (lapack_int) mat.outerStride(); \ 53 | lapack_int matrix_order = (MatrixQR::IsRowMajor) ? LAPACK_ROW_MAJOR : LAPACK_COL_MAJOR; \ 54 | LAPACKE_##LAPACKE_PREFIX##geqrf( matrix_order, m, n, (LAPACKE_TYPE*)mat.data(), lda, (LAPACKE_TYPE*)hCoeffs.data()); \ 55 | hCoeffs.adjointInPlace(); \ 56 | } \ 57 | }; 58 | 59 | EIGEN_LAPACKE_QR_NOPIV(double, double, d) 60 | EIGEN_LAPACKE_QR_NOPIV(float, float, s) 61 | EIGEN_LAPACKE_QR_NOPIV(dcomplex, lapack_complex_double, z) 62 | EIGEN_LAPACKE_QR_NOPIV(scomplex, lapack_complex_float, c) 63 | 64 | } // end namespace internal 65 | 66 | } // end namespace Eigen 67 | 68 | #endif // EIGEN_QR_LAPACKE_H 69 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseCore/MappedSparseMatrix.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2014 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MAPPED_SPARSEMATRIX_H 11 | #define EIGEN_MAPPED_SPARSEMATRIX_H 12 | 13 | namespace Eigen { 14 | 15 | /** \deprecated Use Map > 16 | * \class MappedSparseMatrix 17 | * 18 | * \brief Sparse matrix 19 | * 20 | * \param _Scalar the scalar type, i.e. the type of the coefficients 21 | * 22 | * See http://www.netlib.org/linalg/html_templates/node91.html for details on the storage scheme. 23 | * 24 | */ 25 | namespace internal { 26 | template 27 | struct traits > : traits > 28 | {}; 29 | } // end namespace internal 30 | 31 | template 32 | class MappedSparseMatrix 33 | : public Map > 34 | { 35 | typedef Map > Base; 36 | 37 | public: 38 | 39 | typedef typename Base::StorageIndex StorageIndex; 40 | typedef typename Base::Scalar Scalar; 41 | 42 | inline MappedSparseMatrix(Index rows, Index cols, Index nnz, StorageIndex* outerIndexPtr, StorageIndex* innerIndexPtr, Scalar* valuePtr, StorageIndex* innerNonZeroPtr = 0) 43 | : Base(rows, cols, nnz, outerIndexPtr, innerIndexPtr, valuePtr, innerNonZeroPtr) 44 | {} 45 | 46 | /** Empty destructor */ 47 | inline ~MappedSparseMatrix() {} 48 | }; 49 | 50 | namespace internal { 51 | 52 | template 53 | struct evaluator > 54 | : evaluator > > 55 | { 56 | typedef MappedSparseMatrix<_Scalar,_Options,_StorageIndex> XprType; 57 | typedef evaluator > Base; 58 | 59 | evaluator() : Base() {} 60 | explicit evaluator(const XprType &mat) : Base(mat) {} 61 | }; 62 | 63 | } 64 | 65 | } // end namespace Eigen 66 | 67 | #endif // EIGEN_MAPPED_SPARSEMATRIX_H 68 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseCore/SparseDot.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSE_DOT_H 11 | #define EIGEN_SPARSE_DOT_H 12 | 13 | namespace Eigen { 14 | 15 | template 16 | template 17 | typename internal::traits::Scalar 18 | SparseMatrixBase::dot(const MatrixBase& other) const 19 | { 20 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) 21 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) 22 | EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) 23 | EIGEN_STATIC_ASSERT((internal::is_same::value), 24 | YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 25 | 26 | eigen_assert(size() == other.size()); 27 | eigen_assert(other.size()>0 && "you are using a non initialized vector"); 28 | 29 | internal::evaluator thisEval(derived()); 30 | typename internal::evaluator::InnerIterator i(thisEval, 0); 31 | Scalar res(0); 32 | while (i) 33 | { 34 | res += numext::conj(i.value()) * other.coeff(i.index()); 35 | ++i; 36 | } 37 | return res; 38 | } 39 | 40 | template 41 | template 42 | typename internal::traits::Scalar 43 | SparseMatrixBase::dot(const SparseMatrixBase& other) const 44 | { 45 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) 46 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived) 47 | EIGEN_STATIC_ASSERT_SAME_VECTOR_SIZE(Derived,OtherDerived) 48 | EIGEN_STATIC_ASSERT((internal::is_same::value), 49 | YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) 50 | 51 | eigen_assert(size() == other.size()); 52 | 53 | internal::evaluator thisEval(derived()); 54 | typename internal::evaluator::InnerIterator i(thisEval, 0); 55 | 56 | internal::evaluator otherEval(other.derived()); 57 | typename internal::evaluator::InnerIterator j(otherEval, 0); 58 | 59 | Scalar res(0); 60 | while (i && j) 61 | { 62 | if (i.index()==j.index()) 63 | { 64 | res += numext::conj(i.value()) * j.value(); 65 | ++i; ++j; 66 | } 67 | else if (i.index() 76 | inline typename NumTraits::Scalar>::Real 77 | SparseMatrixBase::squaredNorm() const 78 | { 79 | return numext::real((*this).cwiseAbs2().sum()); 80 | } 81 | 82 | template 83 | inline typename NumTraits::Scalar>::Real 84 | SparseMatrixBase::norm() const 85 | { 86 | using std::sqrt; 87 | return sqrt(squaredNorm()); 88 | } 89 | 90 | template 91 | inline typename NumTraits::Scalar>::Real 92 | SparseMatrixBase::blueNorm() const 93 | { 94 | return internal::blueNorm_impl(*this); 95 | } 96 | } // end namespace Eigen 97 | 98 | #endif // EIGEN_SPARSE_DOT_H 99 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseCore/SparseFuzzy.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2014 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSE_FUZZY_H 11 | #define EIGEN_SPARSE_FUZZY_H 12 | 13 | namespace Eigen { 14 | 15 | template 16 | template 17 | bool SparseMatrixBase::isApprox(const SparseMatrixBase& other, const RealScalar &prec) const 18 | { 19 | const typename internal::nested_eval::type actualA(derived()); 20 | typename internal::conditional::type, 22 | const PlainObject>::type actualB(other.derived()); 23 | 24 | return (actualA - actualB).squaredNorm() <= prec * prec * numext::mini(actualA.squaredNorm(), actualB.squaredNorm()); 25 | } 26 | 27 | } // end namespace Eigen 28 | 29 | #endif // EIGEN_SPARSE_FUZZY_H 30 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseCore/SparseRedux.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2014 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSEREDUX_H 11 | #define EIGEN_SPARSEREDUX_H 12 | 13 | namespace Eigen { 14 | 15 | template 16 | typename internal::traits::Scalar 17 | SparseMatrixBase::sum() const 18 | { 19 | eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); 20 | Scalar res(0); 21 | internal::evaluator thisEval(derived()); 22 | for (Index j=0; j::InnerIterator iter(thisEval,j); iter; ++iter) 24 | res += iter.value(); 25 | return res; 26 | } 27 | 28 | template 29 | typename internal::traits >::Scalar 30 | SparseMatrix<_Scalar,_Options,_Index>::sum() const 31 | { 32 | eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); 33 | if(this->isCompressed()) 34 | return Matrix::Map(m_data.valuePtr(), m_data.size()).sum(); 35 | else 36 | return Base::sum(); 37 | } 38 | 39 | template 40 | typename internal::traits >::Scalar 41 | SparseVector<_Scalar,_Options,_Index>::sum() const 42 | { 43 | eigen_assert(rows()>0 && cols()>0 && "you are using a non initialized matrix"); 44 | return Matrix::Map(m_data.valuePtr(), m_data.size()).sum(); 45 | } 46 | 47 | } // end namespace Eigen 48 | 49 | #endif // EIGEN_SPARSEREDUX_H 50 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseCore/SparseTranspose.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2015 Gael Guennebaud 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_SPARSETRANSPOSE_H 11 | #define EIGEN_SPARSETRANSPOSE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | template 17 | class SparseTransposeImpl 18 | : public SparseMatrixBase > 19 | {}; 20 | 21 | template 22 | class SparseTransposeImpl 23 | : public SparseCompressedBase > 24 | { 25 | typedef SparseCompressedBase > Base; 26 | public: 27 | using Base::derived; 28 | typedef typename Base::Scalar Scalar; 29 | typedef typename Base::StorageIndex StorageIndex; 30 | 31 | inline Index nonZeros() const { return derived().nestedExpression().nonZeros(); } 32 | 33 | inline const Scalar* valuePtr() const { return derived().nestedExpression().valuePtr(); } 34 | inline const StorageIndex* innerIndexPtr() const { return derived().nestedExpression().innerIndexPtr(); } 35 | inline const StorageIndex* outerIndexPtr() const { return derived().nestedExpression().outerIndexPtr(); } 36 | inline const StorageIndex* innerNonZeroPtr() const { return derived().nestedExpression().innerNonZeroPtr(); } 37 | 38 | inline Scalar* valuePtr() { return derived().nestedExpression().valuePtr(); } 39 | inline StorageIndex* innerIndexPtr() { return derived().nestedExpression().innerIndexPtr(); } 40 | inline StorageIndex* outerIndexPtr() { return derived().nestedExpression().outerIndexPtr(); } 41 | inline StorageIndex* innerNonZeroPtr() { return derived().nestedExpression().innerNonZeroPtr(); } 42 | }; 43 | } 44 | 45 | template class TransposeImpl 46 | : public internal::SparseTransposeImpl 47 | { 48 | protected: 49 | typedef internal::SparseTransposeImpl Base; 50 | }; 51 | 52 | namespace internal { 53 | 54 | template 55 | struct unary_evaluator, IteratorBased> 56 | : public evaluator_base > 57 | { 58 | typedef typename evaluator::InnerIterator EvalIterator; 59 | public: 60 | typedef Transpose XprType; 61 | 62 | inline Index nonZerosEstimate() const { 63 | return m_argImpl.nonZerosEstimate(); 64 | } 65 | 66 | class InnerIterator : public EvalIterator 67 | { 68 | public: 69 | EIGEN_STRONG_INLINE InnerIterator(const unary_evaluator& unaryOp, Index outer) 70 | : EvalIterator(unaryOp.m_argImpl,outer) 71 | {} 72 | 73 | Index row() const { return EvalIterator::col(); } 74 | Index col() const { return EvalIterator::row(); } 75 | }; 76 | 77 | enum { 78 | CoeffReadCost = evaluator::CoeffReadCost, 79 | Flags = XprType::Flags 80 | }; 81 | 82 | explicit unary_evaluator(const XprType& op) :m_argImpl(op.nestedExpression()) {} 83 | 84 | protected: 85 | evaluator m_argImpl; 86 | }; 87 | 88 | } // end namespace internal 89 | 90 | } // end namespace Eigen 91 | 92 | #endif // EIGEN_SPARSETRANSPOSE_H 93 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseLU/SparseLU_Utils.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2012 Désiré Nuentsa-Wakam 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | 11 | #ifndef EIGEN_SPARSELU_UTILS_H 12 | #define EIGEN_SPARSELU_UTILS_H 13 | 14 | namespace Eigen { 15 | namespace internal { 16 | 17 | /** 18 | * \brief Count Nonzero elements in the factors 19 | */ 20 | template 21 | void SparseLUImpl::countnz(const Index n, Index& nnzL, Index& nnzU, GlobalLU_t& glu) 22 | { 23 | nnzL = 0; 24 | nnzU = (glu.xusub)(n); 25 | Index nsuper = (glu.supno)(n); 26 | Index jlen; 27 | Index i, j, fsupc; 28 | if (n <= 0 ) return; 29 | // For each supernode 30 | for (i = 0; i <= nsuper; i++) 31 | { 32 | fsupc = glu.xsup(i); 33 | jlen = glu.xlsub(fsupc+1) - glu.xlsub(fsupc); 34 | 35 | for (j = fsupc; j < glu.xsup(i+1); j++) 36 | { 37 | nnzL += jlen; 38 | nnzU += j - fsupc + 1; 39 | jlen--; 40 | } 41 | } 42 | } 43 | 44 | /** 45 | * \brief Fix up the data storage lsub for L-subscripts. 46 | * 47 | * It removes the subscripts sets for structural pruning, 48 | * and applies permutation to the remaining subscripts 49 | * 50 | */ 51 | template 52 | void SparseLUImpl::fixupL(const Index n, const IndexVector& perm_r, GlobalLU_t& glu) 53 | { 54 | Index fsupc, i, j, k, jstart; 55 | 56 | StorageIndex nextl = 0; 57 | Index nsuper = (glu.supno)(n); 58 | 59 | // For each supernode 60 | for (i = 0; i <= nsuper; i++) 61 | { 62 | fsupc = glu.xsup(i); 63 | jstart = glu.xlsub(fsupc); 64 | glu.xlsub(fsupc) = nextl; 65 | for (j = jstart; j < glu.xlsub(fsupc + 1); j++) 66 | { 67 | glu.lsub(nextl) = perm_r(glu.lsub(j)); // Now indexed into P*A 68 | nextl++; 69 | } 70 | for (k = fsupc+1; k < glu.xsup(i+1); k++) 71 | glu.xlsub(k) = nextl; // other columns in supernode i 72 | } 73 | 74 | glu.xlsub(n) = nextl; 75 | } 76 | 77 | } // end namespace internal 78 | 79 | } // end namespace Eigen 80 | #endif // EIGEN_SPARSELU_UTILS_H 81 | -------------------------------------------------------------------------------- /include/Eigen/src/SparseLU/SparseLU_relax_snode.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2012 Désiré Nuentsa-Wakam 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | /* This file is a modified version of heap_relax_snode.c file in SuperLU 11 | * -- SuperLU routine (version 3.0) -- 12 | * Univ. of California Berkeley, Xerox Palo Alto Research Center, 13 | * and Lawrence Berkeley National Lab. 14 | * October 15, 2003 15 | * 16 | * Copyright (c) 1994 by Xerox Corporation. All rights reserved. 17 | * 18 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY 19 | * EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK. 20 | * 21 | * Permission is hereby granted to use or copy this program for any 22 | * purpose, provided the above notices are retained on all copies. 23 | * Permission to modify the code and to distribute modified code is 24 | * granted, provided the above notices are retained, and a notice that 25 | * the code was modified is included with the above copyright notice. 26 | */ 27 | 28 | #ifndef SPARSELU_RELAX_SNODE_H 29 | #define SPARSELU_RELAX_SNODE_H 30 | 31 | namespace Eigen { 32 | 33 | namespace internal { 34 | 35 | /** 36 | * \brief Identify the initial relaxed supernodes 37 | * 38 | * This routine is applied to a column elimination tree. 39 | * It assumes that the matrix has been reordered according to the postorder of the etree 40 | * \param n the number of columns 41 | * \param et elimination tree 42 | * \param relax_columns Maximum number of columns allowed in a relaxed snode 43 | * \param descendants Number of descendants of each node in the etree 44 | * \param relax_end last column in a supernode 45 | */ 46 | template 47 | void SparseLUImpl::relax_snode (const Index n, IndexVector& et, const Index relax_columns, IndexVector& descendants, IndexVector& relax_end) 48 | { 49 | 50 | // compute the number of descendants of each node in the etree 51 | Index parent; 52 | relax_end.setConstant(emptyIdxLU); 53 | descendants.setZero(); 54 | for (Index j = 0; j < n; j++) 55 | { 56 | parent = et(j); 57 | if (parent != n) // not the dummy root 58 | descendants(parent) += descendants(j) + 1; 59 | } 60 | // Identify the relaxed supernodes by postorder traversal of the etree 61 | Index snode_start; // beginning of a snode 62 | for (Index j = 0; j < n; ) 63 | { 64 | parent = et(j); 65 | snode_start = j; 66 | while ( parent != n && descendants(parent) < relax_columns ) 67 | { 68 | j = parent; 69 | parent = et(j); 70 | } 71 | // Found a supernode in postordered etree, j is the last column 72 | relax_end(snode_start) = StorageIndex(j); // Record last column 73 | j++; 74 | // Search for a new leaf 75 | while (descendants(j) != 0 && j < n) j++; 76 | } // End postorder traversal of the etree 77 | 78 | } 79 | 80 | } // end namespace internal 81 | 82 | } // end namespace Eigen 83 | #endif 84 | -------------------------------------------------------------------------------- /include/Eigen/src/StlSupport/details.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Gael Guennebaud 5 | // Copyright (C) 2009 Hauke Heibel 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_STL_DETAILS_H 12 | #define EIGEN_STL_DETAILS_H 13 | 14 | #ifndef EIGEN_ALIGNED_ALLOCATOR 15 | #define EIGEN_ALIGNED_ALLOCATOR Eigen::aligned_allocator 16 | #endif 17 | 18 | namespace Eigen { 19 | 20 | // This one is needed to prevent reimplementing the whole std::vector. 21 | template 22 | class aligned_allocator_indirection : public EIGEN_ALIGNED_ALLOCATOR 23 | { 24 | public: 25 | typedef std::size_t size_type; 26 | typedef std::ptrdiff_t difference_type; 27 | typedef T* pointer; 28 | typedef const T* const_pointer; 29 | typedef T& reference; 30 | typedef const T& const_reference; 31 | typedef T value_type; 32 | 33 | template 34 | struct rebind 35 | { 36 | typedef aligned_allocator_indirection other; 37 | }; 38 | 39 | aligned_allocator_indirection() {} 40 | aligned_allocator_indirection(const aligned_allocator_indirection& ) : EIGEN_ALIGNED_ALLOCATOR() {} 41 | aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR& ) {} 42 | template 43 | aligned_allocator_indirection(const aligned_allocator_indirection& ) {} 44 | template 45 | aligned_allocator_indirection(const EIGEN_ALIGNED_ALLOCATOR& ) {} 46 | ~aligned_allocator_indirection() {} 47 | }; 48 | 49 | #if EIGEN_COMP_MSVC 50 | 51 | // sometimes, MSVC detects, at compile time, that the argument x 52 | // in std::vector::resize(size_t s,T x) won't be aligned and generate an error 53 | // even if this function is never called. Whence this little wrapper. 54 | #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) \ 55 | typename Eigen::internal::conditional< \ 56 | Eigen::internal::is_arithmetic::value, \ 57 | T, \ 58 | Eigen::internal::workaround_msvc_stl_support \ 59 | >::type 60 | 61 | namespace internal { 62 | template struct workaround_msvc_stl_support : public T 63 | { 64 | inline workaround_msvc_stl_support() : T() {} 65 | inline workaround_msvc_stl_support(const T& other) : T(other) {} 66 | inline operator T& () { return *static_cast(this); } 67 | inline operator const T& () const { return *static_cast(this); } 68 | template 69 | inline T& operator=(const OtherT& other) 70 | { T::operator=(other); return *this; } 71 | inline workaround_msvc_stl_support& operator=(const workaround_msvc_stl_support& other) 72 | { T::operator=(other); return *this; } 73 | }; 74 | } 75 | 76 | #else 77 | 78 | #define EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T) T 79 | 80 | #endif 81 | 82 | } 83 | 84 | #endif // EIGEN_STL_DETAILS_H 85 | -------------------------------------------------------------------------------- /include/Eigen/src/misc/Image.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MISC_IMAGE_H 11 | #define EIGEN_MISC_IMAGE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \class image_retval_base 18 | * 19 | */ 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef Matrix< 25 | typename MatrixType::Scalar, 26 | MatrixType::RowsAtCompileTime, // the image is a subspace of the destination space, whose 27 | // dimension is the number of rows of the original matrix 28 | Dynamic, // we don't know at compile time the dimension of the image (the rank) 29 | MatrixType::Options, 30 | MatrixType::MaxRowsAtCompileTime, // the image matrix will consist of columns from the original matrix, 31 | MatrixType::MaxColsAtCompileTime // so it has the same number of rows and at most as many columns. 32 | > ReturnType; 33 | }; 34 | 35 | template struct image_retval_base 36 | : public ReturnByValue > 37 | { 38 | typedef _DecompositionType DecompositionType; 39 | typedef typename DecompositionType::MatrixType MatrixType; 40 | typedef ReturnByValue Base; 41 | 42 | image_retval_base(const DecompositionType& dec, const MatrixType& originalMatrix) 43 | : m_dec(dec), m_rank(dec.rank()), 44 | m_cols(m_rank == 0 ? 1 : m_rank), 45 | m_originalMatrix(originalMatrix) 46 | {} 47 | 48 | inline Index rows() const { return m_dec.rows(); } 49 | inline Index cols() const { return m_cols; } 50 | inline Index rank() const { return m_rank; } 51 | inline const DecompositionType& dec() const { return m_dec; } 52 | inline const MatrixType& originalMatrix() const { return m_originalMatrix; } 53 | 54 | template inline void evalTo(Dest& dst) const 55 | { 56 | static_cast*>(this)->evalTo(dst); 57 | } 58 | 59 | protected: 60 | const DecompositionType& m_dec; 61 | Index m_rank, m_cols; 62 | const MatrixType& m_originalMatrix; 63 | }; 64 | 65 | } // end namespace internal 66 | 67 | #define EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) \ 68 | typedef typename DecompositionType::MatrixType MatrixType; \ 69 | typedef typename MatrixType::Scalar Scalar; \ 70 | typedef typename MatrixType::RealScalar RealScalar; \ 71 | typedef Eigen::internal::image_retval_base Base; \ 72 | using Base::dec; \ 73 | using Base::originalMatrix; \ 74 | using Base::rank; \ 75 | using Base::rows; \ 76 | using Base::cols; \ 77 | image_retval(const DecompositionType& dec, const MatrixType& originalMatrix) \ 78 | : Base(dec, originalMatrix) {} 79 | 80 | } // end namespace Eigen 81 | 82 | #endif // EIGEN_MISC_IMAGE_H 83 | -------------------------------------------------------------------------------- /include/Eigen/src/misc/Kernel.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009 Benoit Jacob 5 | // 6 | // This Source Code Form is subject to the terms of the Mozilla 7 | // Public License v. 2.0. If a copy of the MPL was not distributed 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | 10 | #ifndef EIGEN_MISC_KERNEL_H 11 | #define EIGEN_MISC_KERNEL_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \class kernel_retval_base 18 | * 19 | */ 20 | template 21 | struct traits > 22 | { 23 | typedef typename DecompositionType::MatrixType MatrixType; 24 | typedef Matrix< 25 | typename MatrixType::Scalar, 26 | MatrixType::ColsAtCompileTime, // the number of rows in the "kernel matrix" 27 | // is the number of cols of the original matrix 28 | // so that the product "matrix * kernel = zero" makes sense 29 | Dynamic, // we don't know at compile-time the dimension of the kernel 30 | MatrixType::Options, 31 | MatrixType::MaxColsAtCompileTime, // see explanation for 2nd template parameter 32 | MatrixType::MaxColsAtCompileTime // the kernel is a subspace of the domain space, 33 | // whose dimension is the number of columns of the original matrix 34 | > ReturnType; 35 | }; 36 | 37 | template struct kernel_retval_base 38 | : public ReturnByValue > 39 | { 40 | typedef _DecompositionType DecompositionType; 41 | typedef ReturnByValue Base; 42 | 43 | explicit kernel_retval_base(const DecompositionType& dec) 44 | : m_dec(dec), 45 | m_rank(dec.rank()), 46 | m_cols(m_rank==dec.cols() ? 1 : dec.cols() - m_rank) 47 | {} 48 | 49 | inline Index rows() const { return m_dec.cols(); } 50 | inline Index cols() const { return m_cols; } 51 | inline Index rank() const { return m_rank; } 52 | inline const DecompositionType& dec() const { return m_dec; } 53 | 54 | template inline void evalTo(Dest& dst) const 55 | { 56 | static_cast*>(this)->evalTo(dst); 57 | } 58 | 59 | protected: 60 | const DecompositionType& m_dec; 61 | Index m_rank, m_cols; 62 | }; 63 | 64 | } // end namespace internal 65 | 66 | #define EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) \ 67 | typedef typename DecompositionType::MatrixType MatrixType; \ 68 | typedef typename MatrixType::Scalar Scalar; \ 69 | typedef typename MatrixType::RealScalar RealScalar; \ 70 | typedef Eigen::internal::kernel_retval_base Base; \ 71 | using Base::dec; \ 72 | using Base::rank; \ 73 | using Base::rows; \ 74 | using Base::cols; \ 75 | kernel_retval(const DecompositionType& dec) : Base(dec) {} 76 | 77 | } // end namespace Eigen 78 | 79 | #endif // EIGEN_MISC_KERNEL_H 80 | -------------------------------------------------------------------------------- /include/Eigen/src/misc/RealSvd2x2.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2009-2010 Benoit Jacob 5 | // Copyright (C) 2013-2016 Gael Guennebaud 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | #ifndef EIGEN_REALSVD2X2_H 12 | #define EIGEN_REALSVD2X2_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | 18 | template 19 | void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, 20 | JacobiRotation *j_left, 21 | JacobiRotation *j_right) 22 | { 23 | using std::sqrt; 24 | using std::abs; 25 | Matrix m; 26 | m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)), 27 | numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q)); 28 | JacobiRotation rot1; 29 | RealScalar t = m.coeff(0,0) + m.coeff(1,1); 30 | RealScalar d = m.coeff(1,0) - m.coeff(0,1); 31 | 32 | if(abs(d) < (std::numeric_limits::min)()) 33 | { 34 | rot1.s() = RealScalar(0); 35 | rot1.c() = RealScalar(1); 36 | } 37 | else 38 | { 39 | // If d!=0, then t/d cannot overflow because the magnitude of the 40 | // entries forming d are not too small compared to the ones forming t. 41 | RealScalar u = t / d; 42 | RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u)); 43 | rot1.s() = RealScalar(1) / tmp; 44 | rot1.c() = u / tmp; 45 | } 46 | m.applyOnTheLeft(0,1,rot1); 47 | j_right->makeJacobi(m,0,1); 48 | *j_left = rot1 * j_right->transpose(); 49 | } 50 | 51 | } // end namespace internal 52 | 53 | } // end namespace Eigen 54 | 55 | #endif // EIGEN_REALSVD2X2_H 56 | -------------------------------------------------------------------------------- /include/Eigen/src/misc/lapacke_mangling.h: -------------------------------------------------------------------------------- 1 | #ifndef LAPACK_HEADER_INCLUDED 2 | #define LAPACK_HEADER_INCLUDED 3 | 4 | #ifndef LAPACK_GLOBAL 5 | #if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_) 6 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 7 | #elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER) 8 | #define LAPACK_GLOBAL(lcname,UCNAME) UCNAME 9 | #elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE) 10 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname 11 | #else 12 | #define LAPACK_GLOBAL(lcname,UCNAME) lcname##_ 13 | #endif 14 | #endif 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /include/Eigen/src/plugins/MatrixCwiseUnaryOps.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2009 Gael Guennebaud 5 | // Copyright (C) 2006-2008 Benoit Jacob 6 | // 7 | // This Source Code Form is subject to the terms of the Mozilla 8 | // Public License v. 2.0. If a copy of the MPL was not distributed 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 | 11 | // This file is included into the body of the base classes supporting matrix specific coefficient-wise functions. 12 | // This include MatrixBase and SparseMatrixBase. 13 | 14 | 15 | typedef CwiseUnaryOp, const Derived> CwiseAbsReturnType; 16 | typedef CwiseUnaryOp, const Derived> CwiseAbs2ReturnType; 17 | typedef CwiseUnaryOp, const Derived> CwiseSqrtReturnType; 18 | typedef CwiseUnaryOp, const Derived> CwiseSignReturnType; 19 | typedef CwiseUnaryOp, const Derived> CwiseInverseReturnType; 20 | 21 | /// \returns an expression of the coefficient-wise absolute value of \c *this 22 | /// 23 | /// Example: \include MatrixBase_cwiseAbs.cpp 24 | /// Output: \verbinclude MatrixBase_cwiseAbs.out 25 | /// 26 | EIGEN_DOC_UNARY_ADDONS(cwiseAbs,absolute value) 27 | /// 28 | /// \sa cwiseAbs2() 29 | /// 30 | EIGEN_DEVICE_FUNC 31 | EIGEN_STRONG_INLINE const CwiseAbsReturnType 32 | cwiseAbs() const { return CwiseAbsReturnType(derived()); } 33 | 34 | /// \returns an expression of the coefficient-wise squared absolute value of \c *this 35 | /// 36 | /// Example: \include MatrixBase_cwiseAbs2.cpp 37 | /// Output: \verbinclude MatrixBase_cwiseAbs2.out 38 | /// 39 | EIGEN_DOC_UNARY_ADDONS(cwiseAbs2,squared absolute value) 40 | /// 41 | /// \sa cwiseAbs() 42 | /// 43 | EIGEN_DEVICE_FUNC 44 | EIGEN_STRONG_INLINE const CwiseAbs2ReturnType 45 | cwiseAbs2() const { return CwiseAbs2ReturnType(derived()); } 46 | 47 | /// \returns an expression of the coefficient-wise square root of *this. 48 | /// 49 | /// Example: \include MatrixBase_cwiseSqrt.cpp 50 | /// Output: \verbinclude MatrixBase_cwiseSqrt.out 51 | /// 52 | EIGEN_DOC_UNARY_ADDONS(cwiseSqrt,square-root) 53 | /// 54 | /// \sa cwisePow(), cwiseSquare() 55 | /// 56 | EIGEN_DEVICE_FUNC 57 | inline const CwiseSqrtReturnType 58 | cwiseSqrt() const { return CwiseSqrtReturnType(derived()); } 59 | 60 | /// \returns an expression of the coefficient-wise signum of *this. 61 | /// 62 | /// Example: \include MatrixBase_cwiseSign.cpp 63 | /// Output: \verbinclude MatrixBase_cwiseSign.out 64 | /// 65 | EIGEN_DOC_UNARY_ADDONS(cwiseSign,sign function) 66 | /// 67 | EIGEN_DEVICE_FUNC 68 | inline const CwiseSignReturnType 69 | cwiseSign() const { return CwiseSignReturnType(derived()); } 70 | 71 | 72 | /// \returns an expression of the coefficient-wise inverse of *this. 73 | /// 74 | /// Example: \include MatrixBase_cwiseInverse.cpp 75 | /// Output: \verbinclude MatrixBase_cwiseInverse.out 76 | /// 77 | EIGEN_DOC_UNARY_ADDONS(cwiseInverse,inverse) 78 | /// 79 | /// \sa cwiseProduct() 80 | /// 81 | EIGEN_DEVICE_FUNC 82 | inline const CwiseInverseReturnType 83 | cwiseInverse() const { return CwiseInverseReturnType(derived()); } 84 | 85 | 86 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseCholesky.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_CHOLESKY_H 8 | #define DENSE_CHOLESKY_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include "../Util/CompInfo.h" 14 | 15 | namespace Spectra { 16 | 17 | 18 | /// 19 | /// \ingroup MatOp 20 | /// 21 | /// This class defines the operations related to Cholesky decomposition on a 22 | /// positive definite matrix, \f$B=LL'\f$, where \f$L\f$ is a lower triangular 23 | /// matrix. It is mainly used in the SymGEigsSolver generalized eigen solver 24 | /// in the Cholesky decomposition mode. 25 | /// 26 | template 27 | class DenseCholesky 28 | { 29 | private: 30 | typedef Eigen::Index Index; 31 | typedef Eigen::Matrix Matrix; 32 | typedef Eigen::Matrix Vector; 33 | typedef Eigen::Map MapConstMat; 34 | typedef Eigen::Map MapConstVec; 35 | typedef Eigen::Map MapVec; 36 | typedef const Eigen::Ref ConstGenericMatrix; 37 | 38 | const Index m_n; 39 | Eigen::LLT m_decomp; 40 | int m_info; // status of the decomposition 41 | 42 | public: 43 | /// 44 | /// Constructor to create the matrix operation object. 45 | /// 46 | /// \param mat An **Eigen** matrix object, whose type can be 47 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 48 | /// `Eigen::MatrixXf`), or its mapped version 49 | /// (e.g. `Eigen::Map`). 50 | /// 51 | DenseCholesky(ConstGenericMatrix& mat) : 52 | m_n(mat.rows()), m_info(NOT_COMPUTED) 53 | { 54 | if(mat.rows() != mat.cols()) 55 | throw std::invalid_argument("DenseCholesky: matrix must be square"); 56 | 57 | m_decomp.compute(mat); 58 | m_info = (m_decomp.info() == Eigen::Success) ? 59 | SUCCESSFUL : 60 | NUMERICAL_ISSUE; 61 | } 62 | 63 | /// 64 | /// Returns the number of rows of the underlying matrix. 65 | /// 66 | Index rows() const { return m_n; } 67 | /// 68 | /// Returns the number of columns of the underlying matrix. 69 | /// 70 | Index cols() const { return m_n; } 71 | 72 | /// 73 | /// Returns the status of the computation. 74 | /// The full list of enumeration values can be found in \ref Enumerations. 75 | /// 76 | int info() const { return m_info; } 77 | 78 | /// 79 | /// Performs the lower triangular solving operation \f$y=L^{-1}x\f$. 80 | /// 81 | /// \param x_in Pointer to the \f$x\f$ vector. 82 | /// \param y_out Pointer to the \f$y\f$ vector. 83 | /// 84 | // y_out = inv(L) * x_in 85 | void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const 86 | { 87 | MapConstVec x(x_in, m_n); 88 | MapVec y(y_out, m_n); 89 | y.noalias() = m_decomp.matrixL().solve(x); 90 | } 91 | 92 | /// 93 | /// Performs the upper triangular solving operation \f$y=(L')^{-1}x\f$. 94 | /// 95 | /// \param x_in Pointer to the \f$x\f$ vector. 96 | /// \param y_out Pointer to the \f$y\f$ vector. 97 | /// 98 | // y_out = inv(L') * x_in 99 | void upper_triangular_solve(const Scalar* x_in, Scalar* y_out) const 100 | { 101 | MapConstVec x(x_in, m_n); 102 | MapVec y(y_out, m_n); 103 | y.noalias() = m_decomp.matrixU().solve(x); 104 | } 105 | }; 106 | 107 | 108 | } // namespace Spectra 109 | 110 | #endif // DENSE_CHOLESKY_H 111 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseGenComplexShiftSolve.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_GEN_COMPLEX_SHIFT_SOLVE_H 8 | #define DENSE_GEN_COMPLEX_SHIFT_SOLVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Spectra { 15 | 16 | 17 | /// 18 | /// \ingroup MatOp 19 | /// 20 | /// This class defines the complex shift-solve operation on a general real matrix \f$A\f$, 21 | /// i.e., calculating \f$y=\mathrm{Re}\{(A-\sigma I)^{-1}x\}\f$ for any complex-valued 22 | /// \f$\sigma\f$ and real-valued vector \f$x\f$. It is mainly used in the 23 | /// GenEigsComplexShiftSolver eigen solver. 24 | /// 25 | template 26 | class DenseGenComplexShiftSolve 27 | { 28 | private: 29 | typedef Eigen::Index Index; 30 | typedef Eigen::Matrix Matrix; 31 | typedef Eigen::Matrix Vector; 32 | typedef Eigen::Map MapConstVec; 33 | typedef Eigen::Map MapVec; 34 | typedef const Eigen::Ref ConstGenericMatrix; 35 | 36 | typedef std::complex Complex; 37 | typedef Eigen::Matrix ComplexMatrix; 38 | typedef Eigen::Matrix ComplexVector; 39 | 40 | typedef Eigen::PartialPivLU ComplexSolver; 41 | 42 | ConstGenericMatrix m_mat; 43 | const Index m_n; 44 | ComplexSolver m_solver; 45 | ComplexVector m_x_cache; 46 | 47 | public: 48 | /// 49 | /// Constructor to create the matrix operation object. 50 | /// 51 | /// \param mat An **Eigen** matrix object, whose type can be 52 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 53 | /// `Eigen::MatrixXf`), or its mapped version 54 | /// (e.g. `Eigen::Map`). 55 | /// 56 | DenseGenComplexShiftSolve(ConstGenericMatrix& mat) : 57 | m_mat(mat), m_n(mat.rows()) 58 | { 59 | if(mat.rows() != mat.cols()) 60 | throw std::invalid_argument("DenseGenComplexShiftSolve: matrix must be square"); 61 | } 62 | 63 | /// 64 | /// Return the number of rows of the underlying matrix. 65 | /// 66 | Index rows() const { return m_n; } 67 | /// 68 | /// Return the number of columns of the underlying matrix. 69 | /// 70 | Index cols() const { return m_n; } 71 | 72 | /// 73 | /// Set the complex shift \f$\sigma\f$. 74 | /// 75 | /// \param sigmar Real part of \f$\sigma\f$. 76 | /// \param sigmai Imaginary part of \f$\sigma\f$. 77 | /// 78 | void set_shift(Scalar sigmar, Scalar sigmai) 79 | { 80 | m_solver.compute(m_mat.template cast() - Complex(sigmar, sigmai) * ComplexMatrix::Identity(m_n, m_n)); 81 | m_x_cache.resize(m_n); 82 | m_x_cache.setZero(); 83 | } 84 | 85 | /// 86 | /// Perform the complex shift-solve operation 87 | /// \f$y=\mathrm{Re}\{(A-\sigma I)^{-1}x\}\f$. 88 | /// 89 | /// \param x_in Pointer to the \f$x\f$ vector. 90 | /// \param y_out Pointer to the \f$y\f$ vector. 91 | /// 92 | // y_out = Re( inv(A - sigma * I) * x_in ) 93 | void perform_op(const Scalar* x_in, Scalar* y_out) 94 | { 95 | m_x_cache.real() = MapConstVec(x_in, m_n); 96 | MapVec y(y_out, m_n); 97 | y.noalias() = m_solver.solve(m_x_cache).real(); 98 | } 99 | }; 100 | 101 | 102 | } // namespace Spectra 103 | 104 | #endif // DENSE_GEN_COMPLEX_SHIFT_SOLVE_H 105 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseGenMatProd.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_GEN_MAT_PROD_H 8 | #define DENSE_GEN_MAT_PROD_H 9 | 10 | #include 11 | 12 | namespace Spectra { 13 | 14 | 15 | /// 16 | /// \defgroup MatOp Matrix Operations 17 | /// 18 | /// Define matrix operations on existing matrix objects 19 | /// 20 | 21 | /// 22 | /// \ingroup MatOp 23 | /// 24 | /// This class defines the matrix-vector multiplication operation on a 25 | /// general real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector 26 | /// \f$x\f$. It is mainly used in the GenEigsSolver and 27 | /// SymEigsSolver eigen solvers. 28 | /// 29 | template 30 | class DenseGenMatProd 31 | { 32 | private: 33 | typedef Eigen::Index Index; 34 | typedef Eigen::Matrix Matrix; 35 | typedef Eigen::Matrix Vector; 36 | typedef Eigen::Map MapConstVec; 37 | typedef Eigen::Map MapVec; 38 | typedef const Eigen::Ref ConstGenericMatrix; 39 | 40 | ConstGenericMatrix m_mat; 41 | 42 | public: 43 | /// 44 | /// Constructor to create the matrix operation object. 45 | /// 46 | /// \param mat An **Eigen** matrix object, whose type can be 47 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 48 | /// `Eigen::MatrixXf`), or its mapped version 49 | /// (e.g. `Eigen::Map`). 50 | /// 51 | DenseGenMatProd(ConstGenericMatrix& mat) : 52 | m_mat(mat) 53 | {} 54 | 55 | /// 56 | /// Return the number of rows of the underlying matrix. 57 | /// 58 | Index rows() const { return m_mat.rows(); } 59 | /// 60 | /// Return the number of columns of the underlying matrix. 61 | /// 62 | Index cols() const { return m_mat.cols(); } 63 | 64 | /// 65 | /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. 66 | /// 67 | /// \param x_in Pointer to the \f$x\f$ vector. 68 | /// \param y_out Pointer to the \f$y\f$ vector. 69 | /// 70 | // y_out = A * x_in 71 | void perform_op(const Scalar* x_in, Scalar* y_out) const 72 | { 73 | MapConstVec x(x_in, m_mat.cols()); 74 | MapVec y(y_out, m_mat.rows()); 75 | y.noalias() = m_mat * x; 76 | } 77 | }; 78 | 79 | 80 | } // namespace Spectra 81 | 82 | #endif // DENSE_GEN_MAT_PROD_H 83 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseGenRealShiftSolve.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_GEN_REAL_SHIFT_SOLVE_H 8 | #define DENSE_GEN_REAL_SHIFT_SOLVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace Spectra { 15 | 16 | 17 | /// 18 | /// \ingroup MatOp 19 | /// 20 | /// This class defines the shift-solve operation on a general real matrix \f$A\f$, 21 | /// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and 22 | /// vector \f$x\f$. It is mainly used in the GenEigsRealShiftSolver eigen solver. 23 | /// 24 | template 25 | class DenseGenRealShiftSolve 26 | { 27 | private: 28 | typedef Eigen::Index Index; 29 | typedef Eigen::Matrix Matrix; 30 | typedef Eigen::Matrix Vector; 31 | typedef Eigen::Map MapConstVec; 32 | typedef Eigen::Map MapVec; 33 | typedef const Eigen::Ref ConstGenericMatrix; 34 | 35 | ConstGenericMatrix m_mat; 36 | const Index m_n; 37 | Eigen::PartialPivLU m_solver; 38 | 39 | public: 40 | /// 41 | /// Constructor to create the matrix operation object. 42 | /// 43 | /// \param mat An **Eigen** matrix object, whose type can be 44 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 45 | /// `Eigen::MatrixXf`), or its mapped version 46 | /// (e.g. `Eigen::Map`). 47 | /// 48 | DenseGenRealShiftSolve(ConstGenericMatrix& mat) : 49 | m_mat(mat), m_n(mat.rows()) 50 | { 51 | if(mat.rows() != mat.cols()) 52 | throw std::invalid_argument("DenseGenRealShiftSolve: matrix must be square"); 53 | } 54 | 55 | /// 56 | /// Return the number of rows of the underlying matrix. 57 | /// 58 | Index rows() const { return m_n; } 59 | /// 60 | /// Return the number of columns of the underlying matrix. 61 | /// 62 | Index cols() const { return m_n; } 63 | 64 | /// 65 | /// Set the real shift \f$\sigma\f$. 66 | /// 67 | void set_shift(Scalar sigma) 68 | { 69 | m_solver.compute(m_mat - sigma * Matrix::Identity(m_n, m_n)); 70 | } 71 | 72 | /// 73 | /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. 74 | /// 75 | /// \param x_in Pointer to the \f$x\f$ vector. 76 | /// \param y_out Pointer to the \f$y\f$ vector. 77 | /// 78 | // y_out = inv(A - sigma * I) * x_in 79 | void perform_op(const Scalar* x_in, Scalar* y_out) const 80 | { 81 | MapConstVec x(x_in, m_n); 82 | MapVec y(y_out, m_n); 83 | y.noalias() = m_solver.solve(x); 84 | } 85 | }; 86 | 87 | 88 | } // namespace Spectra 89 | 90 | #endif // DENSE_GEN_REAL_SHIFT_SOLVE_H 91 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseSymMatProd.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_SYM_MAT_PROD_H 8 | #define DENSE_SYM_MAT_PROD_H 9 | 10 | #include 11 | 12 | namespace Spectra { 13 | 14 | 15 | /// 16 | /// \ingroup MatOp 17 | /// 18 | /// This class defines the matrix-vector multiplication operation on a 19 | /// symmetric real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector 20 | /// \f$x\f$. It is mainly used in the SymEigsSolver eigen solver. 21 | /// 22 | template 23 | class DenseSymMatProd 24 | { 25 | private: 26 | typedef Eigen::Index Index; 27 | typedef Eigen::Matrix Matrix; 28 | typedef Eigen::Matrix Vector; 29 | typedef Eigen::Map MapConstVec; 30 | typedef Eigen::Map MapVec; 31 | typedef const Eigen::Ref ConstGenericMatrix; 32 | 33 | ConstGenericMatrix m_mat; 34 | 35 | public: 36 | /// 37 | /// Constructor to create the matrix operation object. 38 | /// 39 | /// \param mat An **Eigen** matrix object, whose type can be 40 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 41 | /// `Eigen::MatrixXf`), or its mapped version 42 | /// (e.g. `Eigen::Map`). 43 | /// 44 | DenseSymMatProd(ConstGenericMatrix& mat) : 45 | m_mat(mat) 46 | {} 47 | 48 | /// 49 | /// Return the number of rows of the underlying matrix. 50 | /// 51 | Index rows() const { return m_mat.rows(); } 52 | /// 53 | /// Return the number of columns of the underlying matrix. 54 | /// 55 | Index cols() const { return m_mat.cols(); } 56 | 57 | /// 58 | /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. 59 | /// 60 | /// \param x_in Pointer to the \f$x\f$ vector. 61 | /// \param y_out Pointer to the \f$y\f$ vector. 62 | /// 63 | // y_out = A * x_in 64 | void perform_op(const Scalar* x_in, Scalar* y_out) const 65 | { 66 | MapConstVec x(x_in, m_mat.cols()); 67 | MapVec y(y_out, m_mat.rows()); 68 | y.noalias() = m_mat.template selfadjointView() * x; 69 | } 70 | }; 71 | 72 | 73 | } // namespace Spectra 74 | 75 | #endif // DENSE_SYM_MAT_PROD_H 76 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/DenseSymShiftSolve.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef DENSE_SYM_SHIFT_SOLVE_H 8 | #define DENSE_SYM_SHIFT_SOLVE_H 9 | 10 | #include 11 | #include 12 | 13 | #include "../LinAlg/BKLDLT.h" 14 | #include "../Util/CompInfo.h" 15 | 16 | namespace Spectra { 17 | 18 | 19 | /// 20 | /// \ingroup MatOp 21 | /// 22 | /// This class defines the shift-solve operation on a real symmetric matrix \f$A\f$, 23 | /// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and 24 | /// vector \f$x\f$. It is mainly used in the SymEigsShiftSolver eigen solver. 25 | /// 26 | template 27 | class DenseSymShiftSolve 28 | { 29 | private: 30 | typedef Eigen::Index Index; 31 | typedef Eigen::Matrix Matrix; 32 | typedef Eigen::Matrix Vector; 33 | typedef Eigen::Map MapConstVec; 34 | typedef Eigen::Map MapVec; 35 | typedef const Eigen::Ref ConstGenericMatrix; 36 | 37 | ConstGenericMatrix m_mat; 38 | const int m_n; 39 | BKLDLT m_solver; 40 | 41 | public: 42 | /// 43 | /// Constructor to create the matrix operation object. 44 | /// 45 | /// \param mat An **Eigen** matrix object, whose type can be 46 | /// `Eigen::Matrix` (e.g. `Eigen::MatrixXd` and 47 | /// `Eigen::MatrixXf`), or its mapped version 48 | /// (e.g. `Eigen::Map`). 49 | /// 50 | DenseSymShiftSolve(ConstGenericMatrix& mat) : 51 | m_mat(mat), m_n(mat.rows()) 52 | { 53 | if(mat.rows() != mat.cols()) 54 | throw std::invalid_argument("DenseSymShiftSolve: matrix must be square"); 55 | } 56 | 57 | /// 58 | /// Return the number of rows of the underlying matrix. 59 | /// 60 | Index rows() const { return m_n; } 61 | /// 62 | /// Return the number of columns of the underlying matrix. 63 | /// 64 | Index cols() const { return m_n; } 65 | 66 | /// 67 | /// Set the real shift \f$\sigma\f$. 68 | /// 69 | void set_shift(Scalar sigma) 70 | { 71 | m_solver.compute(m_mat, Uplo, sigma); 72 | if(m_solver.info() != SUCCESSFUL) 73 | throw std::invalid_argument("DenseSymShiftSolve: factorization failed with the given shift"); 74 | } 75 | 76 | /// 77 | /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. 78 | /// 79 | /// \param x_in Pointer to the \f$x\f$ vector. 80 | /// \param y_out Pointer to the \f$y\f$ vector. 81 | /// 82 | // y_out = inv(A - sigma * I) * x_in 83 | void perform_op(const Scalar* x_in, Scalar* y_out) const 84 | { 85 | MapConstVec x(x_in, m_n); 86 | MapVec y(y_out, m_n); 87 | y.noalias() = m_solver.solve(x); 88 | } 89 | }; 90 | 91 | 92 | } // namespace Spectra 93 | 94 | #endif // DENSE_SYM_SHIFT_SOLVE_H 95 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseCholesky.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_CHOLESKY_H 8 | #define SPARSE_CHOLESKY_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "../Util/CompInfo.h" 15 | 16 | namespace Spectra { 17 | 18 | 19 | /// 20 | /// \ingroup MatOp 21 | /// 22 | /// This class defines the operations related to Cholesky decomposition on a 23 | /// sparse positive definite matrix, \f$B=LL'\f$, where \f$L\f$ is a lower triangular 24 | /// matrix. It is mainly used in the SymGEigsSolver generalized eigen solver 25 | /// in the Cholesky decomposition mode. 26 | /// 27 | template 28 | class SparseCholesky 29 | { 30 | private: 31 | typedef Eigen::Index Index; 32 | typedef Eigen::Matrix Vector; 33 | typedef Eigen::Map MapConstVec; 34 | typedef Eigen::Map MapVec; 35 | typedef Eigen::SparseMatrix SparseMatrix; 36 | typedef const Eigen::Ref ConstGenericSparseMatrix; 37 | 38 | const Index m_n; 39 | Eigen::SimplicialLLT m_decomp; 40 | int m_info; // status of the decomposition 41 | 42 | public: 43 | /// 44 | /// Constructor to create the matrix operation object. 45 | /// 46 | /// \param mat An **Eigen** sparse matrix object, whose type can be 47 | /// `Eigen::SparseMatrix` or its mapped version 48 | /// `Eigen::Map >`. 49 | /// 50 | SparseCholesky(ConstGenericSparseMatrix& mat) : 51 | m_n(mat.rows()) 52 | { 53 | if(mat.rows() != mat.cols()) 54 | throw std::invalid_argument("SparseCholesky: matrix must be square"); 55 | 56 | m_decomp.compute(mat); 57 | m_info = (m_decomp.info() == Eigen::Success) ? 58 | SUCCESSFUL : 59 | NUMERICAL_ISSUE; 60 | } 61 | 62 | /// 63 | /// Returns the number of rows of the underlying matrix. 64 | /// 65 | Index rows() const { return m_n; } 66 | /// 67 | /// Returns the number of columns of the underlying matrix. 68 | /// 69 | Index cols() const { return m_n; } 70 | 71 | /// 72 | /// Returns the status of the computation. 73 | /// The full list of enumeration values can be found in \ref Enumerations. 74 | /// 75 | int info() const { return m_info; } 76 | 77 | /// 78 | /// Performs the lower triangular solving operation \f$y=L^{-1}x\f$. 79 | /// 80 | /// \param x_in Pointer to the \f$x\f$ vector. 81 | /// \param y_out Pointer to the \f$y\f$ vector. 82 | /// 83 | // y_out = inv(L) * x_in 84 | void lower_triangular_solve(const Scalar* x_in, Scalar* y_out) const 85 | { 86 | MapConstVec x(x_in, m_n); 87 | MapVec y(y_out, m_n); 88 | y.noalias() = m_decomp.permutationP() * x; 89 | m_decomp.matrixL().solveInPlace(y); 90 | } 91 | 92 | /// 93 | /// Performs the upper triangular solving operation \f$y=(L')^{-1}x\f$. 94 | /// 95 | /// \param x_in Pointer to the \f$x\f$ vector. 96 | /// \param y_out Pointer to the \f$y\f$ vector. 97 | /// 98 | // y_out = inv(L') * x_in 99 | void upper_triangular_solve(const Scalar* x_in, Scalar* y_out) const 100 | { 101 | MapConstVec x(x_in, m_n); 102 | MapVec y(y_out, m_n); 103 | y.noalias() = m_decomp.matrixU().solve(x); 104 | y = m_decomp.permutationPinv() * y; 105 | } 106 | }; 107 | 108 | 109 | } // namespace Spectra 110 | 111 | #endif // SPARSE_CHOLESKY_H 112 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseGenMatProd.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_GEN_MAT_PROD_H 8 | #define SPARSE_GEN_MAT_PROD_H 9 | 10 | #include 11 | #include 12 | 13 | namespace Spectra { 14 | 15 | 16 | /// 17 | /// \ingroup MatOp 18 | /// 19 | /// This class defines the matrix-vector multiplication operation on a 20 | /// sparse real matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector 21 | /// \f$x\f$. It is mainly used in the GenEigsSolver and SymEigsSolver 22 | /// eigen solvers. 23 | /// 24 | template 25 | class SparseGenMatProd 26 | { 27 | private: 28 | typedef Eigen::Index Index; 29 | typedef Eigen::Matrix Vector; 30 | typedef Eigen::Map MapConstVec; 31 | typedef Eigen::Map MapVec; 32 | typedef Eigen::SparseMatrix SparseMatrix; 33 | typedef const Eigen::Ref ConstGenericSparseMatrix; 34 | 35 | ConstGenericSparseMatrix m_mat; 36 | 37 | public: 38 | /// 39 | /// Constructor to create the matrix operation object. 40 | /// 41 | /// \param mat An **Eigen** sparse matrix object, whose type can be 42 | /// `Eigen::SparseMatrix` or its mapped version 43 | /// `Eigen::Map >`. 44 | /// 45 | SparseGenMatProd(ConstGenericSparseMatrix& mat) : 46 | m_mat(mat) 47 | {} 48 | 49 | /// 50 | /// Return the number of rows of the underlying matrix. 51 | /// 52 | Index rows() const { return m_mat.rows(); } 53 | /// 54 | /// Return the number of columns of the underlying matrix. 55 | /// 56 | Index cols() const { return m_mat.cols(); } 57 | 58 | /// 59 | /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. 60 | /// 61 | /// \param x_in Pointer to the \f$x\f$ vector. 62 | /// \param y_out Pointer to the \f$y\f$ vector. 63 | /// 64 | // y_out = A * x_in 65 | void perform_op(const Scalar* x_in, Scalar* y_out) const 66 | { 67 | MapConstVec x(x_in, m_mat.cols()); 68 | MapVec y(y_out, m_mat.rows()); 69 | y.noalias() = m_mat * x; 70 | } 71 | }; 72 | 73 | 74 | } // namespace Spectra 75 | 76 | #endif // SPARSE_GEN_MAT_PROD_H 77 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseGenRealShiftSolve.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_GEN_REAL_SHIFT_SOLVE_H 8 | #define SPARSE_GEN_REAL_SHIFT_SOLVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Spectra { 16 | 17 | 18 | /// 19 | /// \ingroup MatOp 20 | /// 21 | /// This class defines the shift-solve operation on a sparse real matrix \f$A\f$, 22 | /// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and 23 | /// vector \f$x\f$. It is mainly used in the GenEigsRealShiftSolver eigen solver. 24 | /// 25 | template 26 | class SparseGenRealShiftSolve 27 | { 28 | private: 29 | typedef Eigen::Index Index; 30 | typedef Eigen::Matrix Vector; 31 | typedef Eigen::Map MapConstVec; 32 | typedef Eigen::Map MapVec; 33 | typedef Eigen::SparseMatrix SparseMatrix; 34 | typedef const Eigen::Ref ConstGenericSparseMatrix; 35 | 36 | ConstGenericSparseMatrix m_mat; 37 | const int m_n; 38 | Eigen::SparseLU m_solver; 39 | 40 | public: 41 | /// 42 | /// Constructor to create the matrix operation object. 43 | /// 44 | /// \param mat An **Eigen** sparse matrix object, whose type can be 45 | /// `Eigen::SparseMatrix` or its mapped version 46 | /// `Eigen::Map >`. 47 | /// 48 | SparseGenRealShiftSolve(ConstGenericSparseMatrix& mat) : 49 | m_mat(mat), m_n(mat.rows()) 50 | { 51 | if(mat.rows() != mat.cols()) 52 | throw std::invalid_argument("SparseGenRealShiftSolve: matrix must be square"); 53 | } 54 | 55 | /// 56 | /// Return the number of rows of the underlying matrix. 57 | /// 58 | Index rows() const { return m_n; } 59 | /// 60 | /// Return the number of columns of the underlying matrix. 61 | /// 62 | Index cols() const { return m_n; } 63 | 64 | /// 65 | /// Set the real shift \f$\sigma\f$. 66 | /// 67 | void set_shift(Scalar sigma) 68 | { 69 | SparseMatrix I(m_n, m_n); 70 | I.setIdentity(); 71 | 72 | m_solver.compute(m_mat - sigma * I); 73 | if(m_solver.info() != Eigen::Success) 74 | throw std::invalid_argument("SparseGenRealShiftSolve: factorization failed with the given shift"); 75 | } 76 | 77 | /// 78 | /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. 79 | /// 80 | /// \param x_in Pointer to the \f$x\f$ vector. 81 | /// \param y_out Pointer to the \f$y\f$ vector. 82 | /// 83 | // y_out = inv(A - sigma * I) * x_in 84 | void perform_op(const Scalar* x_in, Scalar* y_out) const 85 | { 86 | MapConstVec x(x_in, m_n); 87 | MapVec y(y_out, m_n); 88 | y.noalias() = m_solver.solve(x); 89 | } 90 | }; 91 | 92 | 93 | } // namespace Spectra 94 | 95 | #endif // SPARSE_GEN_REAL_SHIFT_SOLVE_H 96 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseRegularInverse.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_REGULAR_INVERSE_H 8 | #define SPARSE_REGULAR_INVERSE_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Spectra { 16 | 17 | 18 | /// 19 | /// \ingroup MatOp 20 | /// 21 | /// This class defines matrix operations required by the generalized eigen solver 22 | /// in the regular inverse mode. For a sparse and positive definite matrix \f$B\f$, 23 | /// it implements the matrix-vector product \f$y=Bx\f$ and the linear equation 24 | /// solving operation \f$y=B^{-1}x\f$. 25 | /// 26 | /// This class is intended to be used with the SymGEigsSolver generalized eigen solver 27 | /// in the regular inverse mode. 28 | /// 29 | template 30 | class SparseRegularInverse 31 | { 32 | private: 33 | typedef Eigen::Index Index; 34 | typedef Eigen::Matrix Vector; 35 | typedef Eigen::Map MapConstVec; 36 | typedef Eigen::Map MapVec; 37 | typedef Eigen::SparseMatrix SparseMatrix; 38 | typedef const Eigen::Ref ConstGenericSparseMatrix; 39 | 40 | ConstGenericSparseMatrix m_mat; 41 | const int m_n; 42 | Eigen::ConjugateGradient m_cg; 43 | 44 | public: 45 | /// 46 | /// Constructor to create the matrix operation object. 47 | /// 48 | /// \param mat An **Eigen** sparse matrix object, whose type can be 49 | /// `Eigen::SparseMatrix` or its mapped version 50 | /// `Eigen::Map >`. 51 | /// 52 | SparseRegularInverse(ConstGenericSparseMatrix& mat) : 53 | m_mat(mat), m_n(mat.rows()) 54 | { 55 | if(mat.rows() != mat.cols()) 56 | throw std::invalid_argument("SparseRegularInverse: matrix must be square"); 57 | 58 | m_cg.compute(mat); 59 | } 60 | 61 | /// 62 | /// Return the number of rows of the underlying matrix. 63 | /// 64 | Index rows() const { return m_n; } 65 | /// 66 | /// Return the number of columns of the underlying matrix. 67 | /// 68 | Index cols() const { return m_n; } 69 | 70 | /// 71 | /// Perform the solving operation \f$y=B^{-1}x\f$. 72 | /// 73 | /// \param x_in Pointer to the \f$x\f$ vector. 74 | /// \param y_out Pointer to the \f$y\f$ vector. 75 | /// 76 | // y_out = inv(B) * x_in 77 | void solve(const Scalar* x_in, Scalar* y_out) const 78 | { 79 | MapConstVec x(x_in, m_n); 80 | MapVec y(y_out, m_n); 81 | y.noalias() = m_cg.solve(x); 82 | } 83 | 84 | /// 85 | /// Perform the matrix-vector multiplication operation \f$y=Bx\f$. 86 | /// 87 | /// \param x_in Pointer to the \f$x\f$ vector. 88 | /// \param y_out Pointer to the \f$y\f$ vector. 89 | /// 90 | // y_out = B * x_in 91 | void mat_prod(const Scalar* x_in, Scalar* y_out) const 92 | { 93 | MapConstVec x(x_in, m_n); 94 | MapVec y(y_out, m_n); 95 | y.noalias() = m_mat.template selfadjointView() * x; 96 | } 97 | }; 98 | 99 | 100 | } // namespace Spectra 101 | 102 | #endif // SPARSE_REGULAR_INVERSE_H 103 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseSymMatProd.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_SYM_MAT_PROD_H 8 | #define SPARSE_SYM_MAT_PROD_H 9 | 10 | #include 11 | #include 12 | 13 | namespace Spectra { 14 | 15 | 16 | /// 17 | /// \ingroup MatOp 18 | /// 19 | /// This class defines the matrix-vector multiplication operation on a 20 | /// sparse real symmetric matrix \f$A\f$, i.e., calculating \f$y=Ax\f$ for any vector 21 | /// \f$x\f$. It is mainly used in the SymEigsSolver eigen solver. 22 | /// 23 | template 24 | class SparseSymMatProd 25 | { 26 | private: 27 | typedef Eigen::Index Index; 28 | typedef Eigen::Matrix Vector; 29 | typedef Eigen::Map MapConstVec; 30 | typedef Eigen::Map MapVec; 31 | typedef Eigen::SparseMatrix SparseMatrix; 32 | typedef const Eigen::Ref ConstGenericSparseMatrix; 33 | 34 | ConstGenericSparseMatrix m_mat; 35 | 36 | public: 37 | /// 38 | /// Constructor to create the matrix operation object. 39 | /// 40 | /// \param mat An **Eigen** sparse matrix object, whose type can be 41 | /// `Eigen::SparseMatrix` or its mapped version 42 | /// `Eigen::Map >`. 43 | /// 44 | SparseSymMatProd(ConstGenericSparseMatrix& mat) : 45 | m_mat(mat) 46 | {} 47 | 48 | /// 49 | /// Return the number of rows of the underlying matrix. 50 | /// 51 | Index rows() const { return m_mat.rows(); } 52 | /// 53 | /// Return the number of columns of the underlying matrix. 54 | /// 55 | Index cols() const { return m_mat.cols(); } 56 | 57 | /// 58 | /// Perform the matrix-vector multiplication operation \f$y=Ax\f$. 59 | /// 60 | /// \param x_in Pointer to the \f$x\f$ vector. 61 | /// \param y_out Pointer to the \f$y\f$ vector. 62 | /// 63 | // y_out = A * x_in 64 | void perform_op(const Scalar* x_in, Scalar* y_out) const 65 | { 66 | MapConstVec x(x_in, m_mat.cols()); 67 | MapVec y(y_out, m_mat.rows()); 68 | y.noalias() = m_mat.template selfadjointView() * x; 69 | } 70 | }; 71 | 72 | 73 | } // namespace Spectra 74 | 75 | #endif // SPARSE_SYM_MAT_PROD_H 76 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/SparseSymShiftSolve.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SPARSE_SYM_SHIFT_SOLVE_H 8 | #define SPARSE_SYM_SHIFT_SOLVE_H 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Spectra { 16 | 17 | 18 | /// 19 | /// \ingroup MatOp 20 | /// 21 | /// This class defines the shift-solve operation on a sparse real symmetric matrix \f$A\f$, 22 | /// i.e., calculating \f$y=(A-\sigma I)^{-1}x\f$ for any real \f$\sigma\f$ and 23 | /// vector \f$x\f$. It is mainly used in the SymEigsShiftSolver eigen solver. 24 | /// 25 | template 26 | class SparseSymShiftSolve 27 | { 28 | private: 29 | typedef Eigen::Index Index; 30 | typedef Eigen::Matrix Vector; 31 | typedef Eigen::Map MapConstVec; 32 | typedef Eigen::Map MapVec; 33 | typedef Eigen::SparseMatrix SparseMatrix; 34 | typedef const Eigen::Ref ConstGenericSparseMatrix; 35 | 36 | ConstGenericSparseMatrix m_mat; 37 | const int m_n; 38 | Eigen::SparseLU m_solver; 39 | 40 | public: 41 | /// 42 | /// Constructor to create the matrix operation object. 43 | /// 44 | /// \param mat An **Eigen** sparse matrix object, whose type can be 45 | /// `Eigen::SparseMatrix` or its mapped version 46 | /// `Eigen::Map >`. 47 | /// 48 | SparseSymShiftSolve(ConstGenericSparseMatrix& mat) : 49 | m_mat(mat), m_n(mat.rows()) 50 | { 51 | if(mat.rows() != mat.cols()) 52 | throw std::invalid_argument("SparseSymShiftSolve: matrix must be square"); 53 | } 54 | 55 | /// 56 | /// Return the number of rows of the underlying matrix. 57 | /// 58 | Index rows() const { return m_n; } 59 | /// 60 | /// Return the number of columns of the underlying matrix. 61 | /// 62 | Index cols() const { return m_n; } 63 | 64 | /// 65 | /// Set the real shift \f$\sigma\f$. 66 | /// 67 | void set_shift(Scalar sigma) 68 | { 69 | SparseMatrix mat = m_mat.template selfadjointView(); 70 | SparseMatrix identity(m_n, m_n); 71 | identity.setIdentity(); 72 | mat = mat - sigma * identity; 73 | m_solver.isSymmetric(true); 74 | m_solver.compute(mat); 75 | if(m_solver.info() != Eigen::Success) 76 | throw std::invalid_argument("SparseSymShiftSolve: factorization failed with the given shift"); 77 | } 78 | 79 | /// 80 | /// Perform the shift-solve operation \f$y=(A-\sigma I)^{-1}x\f$. 81 | /// 82 | /// \param x_in Pointer to the \f$x\f$ vector. 83 | /// \param y_out Pointer to the \f$y\f$ vector. 84 | /// 85 | // y_out = inv(A - sigma * I) * x_in 86 | void perform_op(const Scalar* x_in, Scalar* y_out) const 87 | { 88 | MapConstVec x(x_in, m_n); 89 | MapVec y(y_out, m_n); 90 | y.noalias() = m_solver.solve(x); 91 | } 92 | }; 93 | 94 | 95 | } // namespace Spectra 96 | 97 | #endif // SPARSE_SYM_SHIFT_SOLVE_H 98 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/internal/SymGEigsCholeskyOp.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SYM_GEIGS_CHOLESKY_OP_H 8 | #define SYM_GEIGS_CHOLESKY_OP_H 9 | 10 | #include 11 | #include "../DenseSymMatProd.h" 12 | #include "../DenseCholesky.h" 13 | 14 | namespace Spectra { 15 | 16 | 17 | /// 18 | /// \ingroup Operators 19 | /// 20 | /// This class defines the matrix operation for generalized eigen solver in the 21 | /// Cholesky decomposition mode. It calculates \f$y=L^{-1}A(L')^{-1}x\f$ for any 22 | /// vector \f$x\f$, where \f$L\f$ is the Cholesky decomposition of \f$B\f$. 23 | /// This class is intended for internal use. 24 | /// 25 | template < typename Scalar = double, 26 | typename OpType = DenseSymMatProd, 27 | typename BOpType = DenseCholesky > 28 | class SymGEigsCholeskyOp 29 | { 30 | private: 31 | typedef Eigen::Index Index; 32 | typedef Eigen::Matrix Matrix; 33 | typedef Eigen::Matrix Vector; 34 | 35 | OpType& m_op; 36 | BOpType& m_Bop; 37 | Vector m_cache; // temporary working space 38 | 39 | public: 40 | /// 41 | /// Constructor to create the matrix operation object. 42 | /// 43 | /// \param op Pointer to the \f$A\f$ matrix operation object. 44 | /// \param Bop Pointer to the \f$B\f$ matrix operation object. 45 | /// 46 | SymGEigsCholeskyOp(OpType& op, BOpType& Bop) : 47 | m_op(op), m_Bop(Bop), m_cache(op.rows()) 48 | {} 49 | 50 | /// 51 | /// Return the number of rows of the underlying matrix. 52 | /// 53 | Index rows() const { return m_Bop.rows(); } 54 | /// 55 | /// Return the number of columns of the underlying matrix. 56 | /// 57 | Index cols() const { return m_Bop.rows(); } 58 | 59 | /// 60 | /// Perform the matrix operation \f$y=L^{-1}A(L')^{-1}x\f$. 61 | /// 62 | /// \param x_in Pointer to the \f$x\f$ vector. 63 | /// \param y_out Pointer to the \f$y\f$ vector. 64 | /// 65 | // y_out = inv(L) * A * inv(L') * x_in 66 | void perform_op(const Scalar* x_in, Scalar* y_out) 67 | { 68 | m_Bop.upper_triangular_solve(x_in, y_out); 69 | m_op.perform_op(y_out, m_cache.data()); 70 | m_Bop.lower_triangular_solve(m_cache.data(), y_out); 71 | } 72 | }; 73 | 74 | 75 | } // namespace Spectra 76 | 77 | #endif // SYM_GEIGS_CHOLESKY_OP_H 78 | -------------------------------------------------------------------------------- /include/Spectra/MatOp/internal/SymGEigsRegInvOp.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2017-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SYM_GEIGS_REG_INV_OP_H 8 | #define SYM_GEIGS_REG_INV_OP_H 9 | 10 | #include 11 | #include "../SparseSymMatProd.h" 12 | #include "../SparseRegularInverse.h" 13 | 14 | namespace Spectra { 15 | 16 | 17 | /// 18 | /// \ingroup Operators 19 | /// 20 | /// This class defines the matrix operation for generalized eigen solver in the 21 | /// regular inverse mode. This class is intended for internal use. 22 | /// 23 | template < typename Scalar = double, 24 | typename OpType = SparseSymMatProd, 25 | typename BOpType = SparseRegularInverse > 26 | class SymGEigsRegInvOp 27 | { 28 | private: 29 | typedef Eigen::Index Index; 30 | typedef Eigen::Matrix Matrix; 31 | typedef Eigen::Matrix Vector; 32 | 33 | OpType& m_op; 34 | BOpType& m_Bop; 35 | Vector m_cache; // temporary working space 36 | 37 | public: 38 | /// 39 | /// Constructor to create the matrix operation object. 40 | /// 41 | /// \param op Pointer to the \f$A\f$ matrix operation object. 42 | /// \param Bop Pointer to the \f$B\f$ matrix operation object. 43 | /// 44 | SymGEigsRegInvOp(OpType& op, BOpType& Bop) : 45 | m_op(op), m_Bop(Bop), m_cache(op.rows()) 46 | {} 47 | 48 | /// 49 | /// Return the number of rows of the underlying matrix. 50 | /// 51 | Index rows() const { return m_Bop.rows(); } 52 | /// 53 | /// Return the number of columns of the underlying matrix. 54 | /// 55 | Index cols() const { return m_Bop.rows(); } 56 | 57 | /// 58 | /// Perform the matrix operation \f$y=B^{-1}Ax\f$. 59 | /// 60 | /// \param x_in Pointer to the \f$x\f$ vector. 61 | /// \param y_out Pointer to the \f$y\f$ vector. 62 | /// 63 | // y_out = inv(B) * A * x_in 64 | void perform_op(const Scalar* x_in, Scalar* y_out) 65 | { 66 | m_op.perform_op(x_in, m_cache.data()); 67 | m_Bop.solve(m_cache.data(), y_out); 68 | } 69 | }; 70 | 71 | 72 | } // namespace Spectra 73 | 74 | #endif // SYM_GEIGS_REG_INV_OP_H 75 | -------------------------------------------------------------------------------- /include/Spectra/Util/CompInfo.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef COMP_INFO_H 8 | #define COMP_INFO_H 9 | 10 | namespace Spectra { 11 | 12 | 13 | /// 14 | /// \ingroup Enumerations 15 | /// 16 | /// The enumeration to report the status of computation. 17 | /// 18 | enum COMPUTATION_INFO 19 | { 20 | SUCCESSFUL = 0, ///< Computation was successful. 21 | 22 | NOT_COMPUTED, ///< Used in eigen solvers, indicating that computation 23 | ///< has not been conducted. Users should call 24 | ///< the `compute()` member function of solvers. 25 | 26 | NOT_CONVERGING, ///< Used in eigen solvers, indicating that some eigenvalues 27 | ///< did not converge. The `compute()` 28 | ///< function returns the number of converged eigenvalues. 29 | 30 | NUMERICAL_ISSUE ///< Used in Cholesky decomposition, indicating that the 31 | ///< matrix is not positive definite. 32 | }; 33 | 34 | 35 | } // namespace Spectra 36 | 37 | #endif // COMP_INFO_H 38 | -------------------------------------------------------------------------------- /include/Spectra/Util/GEigsMode.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef GEIGS_MODE_H 8 | #define GEIGS_MODE_H 9 | 10 | namespace Spectra { 11 | 12 | 13 | /// 14 | /// \ingroup Enumerations 15 | /// 16 | /// The enumeration to specify the mode of generalized eigenvalue solver. 17 | /// 18 | enum GEIGS_MODE 19 | { 20 | GEIGS_CHOLESKY = 0, ///< Using Cholesky decomposition to solve generalized eigenvalues. 21 | 22 | GEIGS_REGULAR_INVERSE, ///< Regular inverse mode for generalized eigenvalue solver. 23 | 24 | GEIGS_SHIFT_INVERT, ///< Shift-and-invert mode for generalized eigenvalue solver. 25 | 26 | GEIGS_BUCKLING, ///< Buckling mode for generalized eigenvalue solver. 27 | 28 | GEIGS_CAYLEY ///< Cayley transformation mode for generalized eigenvalue solver. 29 | }; 30 | 31 | 32 | } // namespace Spectra 33 | 34 | #endif // GEIGS_MODE_H 35 | -------------------------------------------------------------------------------- /include/Spectra/Util/SimpleRandom.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2016-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef SIMPLE_RANDOM_H 8 | #define SIMPLE_RANDOM_H 9 | 10 | #include 11 | 12 | /// \cond 13 | 14 | namespace Spectra { 15 | 16 | 17 | // We need a simple pseudo random number generator here: 18 | // 1. It is used to generate initial and restarted residual vector. 19 | // 2. It is not necessary to be so "random" and advanced. All we hope 20 | // is that the residual vector is not in the space spanned by the 21 | // current Krylov space. This should be met almost surely. 22 | // 3. We don't want to call RNG in C++, since we actually want the 23 | // algorithm to be deterministic. Also, calling RNG in C/C++ is not 24 | // allowed in R packages submitted to CRAN. 25 | // 4. The method should be as simple as possible, so an LCG is enough. 26 | // 5. Based on public domain code by Ray Gardner 27 | // http://stjarnhimlen.se/snippets/rg_rand.c 28 | 29 | 30 | template 31 | class SimpleRandom 32 | { 33 | private: 34 | typedef Eigen::Index Index; 35 | typedef Eigen::Matrix Vector; 36 | 37 | const unsigned int m_a; // multiplier 38 | const unsigned long m_max; // 2^31 - 1 39 | long m_rand; 40 | 41 | inline long next_long_rand(long seed) 42 | { 43 | unsigned long lo, hi; 44 | 45 | lo = m_a * (long)(seed & 0xFFFF); 46 | hi = m_a * (long)((unsigned long)seed >> 16); 47 | lo += (hi & 0x7FFF) << 16; 48 | if(lo > m_max) 49 | { 50 | lo &= m_max; 51 | ++lo; 52 | } 53 | lo += hi >> 15; 54 | if(lo > m_max) 55 | { 56 | lo &= m_max; 57 | ++lo; 58 | } 59 | return (long)lo; 60 | } 61 | public: 62 | SimpleRandom(unsigned long init_seed) : 63 | m_a(16807), 64 | m_max(2147483647L), 65 | m_rand(init_seed ? (init_seed & m_max) : 1) 66 | {} 67 | 68 | Scalar random() 69 | { 70 | m_rand = next_long_rand(m_rand); 71 | return Scalar(m_rand) / Scalar(m_max) - Scalar(0.5); 72 | } 73 | 74 | // Vector of random numbers of type Scalar 75 | // Ranging from -0.5 to 0.5 76 | Vector random_vec(const Index len) 77 | { 78 | Vector res(len); 79 | for(Index i = 0; i < len; i++) 80 | { 81 | m_rand = next_long_rand(m_rand); 82 | res[i] = Scalar(m_rand) / Scalar(m_max) - Scalar(0.5); 83 | } 84 | return res; 85 | } 86 | }; 87 | 88 | 89 | } // namespace Spectra 90 | 91 | /// \endcond 92 | 93 | #endif // SIMPLE_RANDOM_H 94 | -------------------------------------------------------------------------------- /include/Spectra/Util/TypeTraits.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2018-2019 Yixuan Qiu 2 | // 3 | // This Source Code Form is subject to the terms of the Mozilla 4 | // Public License v. 2.0. If a copy of the MPL was not distributed 5 | // with this file, You can obtain one at https://mozilla.org/MPL/2.0/. 6 | 7 | #ifndef TYPE_TRAITS_H 8 | #define TYPE_TRAITS_H 9 | 10 | #include 11 | #include 12 | 13 | /// \cond 14 | 15 | namespace Spectra { 16 | 17 | 18 | // For a real value type "Scalar", we want to know its smallest 19 | // positive value, i.e., std::numeric_limits::min(). 20 | // However, we must take non-standard value types into account, 21 | // so we rely on Eigen::NumTraits. 22 | // 23 | // Eigen::NumTraits has defined epsilon() and lowest(), but 24 | // lowest() means negative highest(), which is a very small 25 | // negative value. 26 | // 27 | // Therefore, we manually define this limit, and use eplison()^3 28 | // to mimic it for non-standard types. 29 | 30 | // Generic definition 31 | template 32 | struct TypeTraits 33 | { 34 | static inline Scalar min() 35 | { 36 | return Eigen::numext::pow(Eigen::NumTraits::epsilon(), Scalar(3)); 37 | } 38 | }; 39 | 40 | // Full specialization 41 | template <> 42 | struct TypeTraits 43 | { 44 | static inline float min() 45 | { 46 | return std::numeric_limits::min(); 47 | } 48 | }; 49 | 50 | template <> 51 | struct TypeTraits 52 | { 53 | static inline double min() 54 | { 55 | return std::numeric_limits::min(); 56 | } 57 | }; 58 | 59 | template <> 60 | struct TypeTraits 61 | { 62 | static inline long double min() 63 | { 64 | return std::numeric_limits::min(); 65 | } 66 | }; 67 | 68 | 69 | } // namespace Spectra 70 | 71 | /// \endcond 72 | 73 | #endif // TYPE_TRAITS_H 74 | -------------------------------------------------------------------------------- /include/alstructure.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPCA_ALSTRUCTURE_H_ 2 | #define PROPCA_ALSTRUCTURE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "genotype.h" 9 | #include "matmult.h" 10 | 11 | 12 | struct options { 13 | std::string GENOTYPE_FILE_PATH; 14 | std::string ROWSPACE_FILE_PATH; 15 | std::string INITIAL_FILE_PATH; 16 | std::string FREQ_FILE_PATH; 17 | std::string OUTPUT_PATH; 18 | int max_iterations; 19 | int num_of_evec; 20 | bool getaccuracy; 21 | bool debugmode; 22 | double convergence_limit; 23 | bool memory_efficient; 24 | bool fast_mode; 25 | bool missing; 26 | bool text_version; 27 | bool fhat_version; 28 | bool fhattrunc_version; 29 | int nthreads; 30 | unsigned int seed; 31 | bool given_seed; 32 | }; 33 | 34 | 35 | class ALStructure { 36 | public: 37 | options command_line_opts; 38 | 39 | Genotype g; 40 | MatrixXdr geno_matrix; //(p,n) 41 | MatMult mm; 42 | 43 | Eigen::VectorXd D; //(n,1) for LSE 44 | unsigned int nops; // number ops for LSE 45 | 46 | MatrixXdr V; // (n,k) for truncated ALS 47 | MatrixXdr Fhat; // (p,n) for truncated ALS 48 | MatrixXdr Phat; // (p,k) for truncated ALS 49 | MatrixXdr Qhat; // (k,n) for truncated ALS 50 | MatrixXdr Qhat_old; // (k,n) for truncated ALS 51 | MatrixXdr diff; // (k,n) for truncated ALS 52 | 53 | double rmse; 54 | int MAX_ITER; 55 | int k, p, n; 56 | long long int niter; 57 | int seed; 58 | 59 | //std::ofstream fp; 60 | 61 | clock_t total_begin; //= clock(); 62 | 63 | bool debug; // = false; 64 | double convergence_limit; 65 | bool memory_efficient; // = false; 66 | bool missing; // = false; 67 | bool fast_mode; // = true; 68 | bool text_version; // = false; 69 | bool fhat_version; // = false; 70 | bool fhattrunc_version; // = false; 71 | int nthreads; // = 1; 72 | std::string output_path; 73 | 74 | ALStructure() {} 75 | ALStructure(int argc, char const *argv[]); 76 | 77 | void printCorrectUsage(void); 78 | 79 | void solve_for_Qhat(void); 80 | void solve_for_Phat(void); 81 | 82 | void initialize(std::default_random_engine &prng_eng); 83 | void truncated_alternating_least_squares(bool projection_mode = false); 84 | 85 | int run(); 86 | 87 | void write_matrix(MatrixXdr &mat, const std::string file_name); 88 | void write_matrix_maf(MatrixXdr &mat, const std::string file_name); 89 | void write_vector(Eigen::VectorXd &vec, const std::string file_name); 90 | 91 | unsigned int rows(); // rows for Spectra 92 | unsigned int cols(); // cols for Spectra 93 | void perform_op(const double* x_in, double* y_out); // operation for Spectra 94 | 95 | }; 96 | 97 | #endif // PROPCA_ALSTRUCTURE_H_ 98 | -------------------------------------------------------------------------------- /include/genotype.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPCA_GENOTYPE_H_ 2 | #define PROPCA_GENOTYPE_H_ 3 | 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "storage.h" 14 | 15 | 16 | // Storing in RowMajor Form 17 | typedef Eigen::Matrix MatrixXdr; 18 | 19 | 20 | class Genotype { 21 | std::vector< std::vector > msb; 22 | std::vector< std::vector > lsb; 23 | std::vector columnmeans; 24 | std::vector columnsum; 25 | 26 | public: 27 | unsigned char mask; 28 | int wordsize; 29 | unsigned int unitsperword; 30 | int unitsize; 31 | int nrow, ncol; 32 | unsigned char *gtype; 33 | 34 | int Nsnp, Nindv; 35 | int Nsegments_hori, Nsegments_ver; 36 | int segment_size_hori, segment_size_ver; 37 | int Nbits_hori, Nbits_ver; 38 | int Nelements_hori, Nelements_ver; 39 | std::vector< std::vector > p; 40 | std::vector rowsum; 41 | std::vector rowsqsum; 42 | 43 | // std::vector< std::vector > p_eff; 44 | // std::vector< std::vector > q_eff; 45 | 46 | std::vector< std::vector > not_O_j; 47 | std::vector< std::vector > not_O_i; 48 | 49 | void init_means(bool is_missing); 50 | 51 | float get_observed_pj(const std::string &line); 52 | float get_observed_pj(const unsigned char* line); 53 | 54 | void read_txt_naive(std::string filename, bool allow_missing); 55 | void read_txt_mailman(std::string filename, bool allow_missing); 56 | 57 | void read_plink(std::string filenameprefix, bool allow_missing, bool mailman_mode); 58 | void read_bed(std::string filename, bool allow_missing, bool mailman_mode); 59 | void read_bed_mailman(std::string filename, bool allow_missing); 60 | void read_bed_naive(std::string filename, bool allow_missing); 61 | 62 | int countlines(std::string filename); 63 | void set_metadata(); 64 | 65 | double get_geno(int snpindex, int indvindex, bool var_normalize); 66 | double get_col_mean(int snpindex); 67 | double get_col_sum(int snpindex); 68 | double get_col_std(int snpindex); 69 | void update_col_mean(int snpindex, double value); 70 | 71 | void generate_eigen_geno(MatrixXdr &geno_matrix, bool subtract_means, bool var_normalize); 72 | }; 73 | 74 | #endif // PROPCA_GENOTYPE_H_ 75 | -------------------------------------------------------------------------------- /include/helper.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPCA_HELPER_H_ 2 | #define PROPCA_HELPER_H_ 3 | 4 | 5 | #include "time.h" 6 | 7 | #include 8 | 9 | 10 | extern struct timespec t0; 11 | 12 | struct timespec elapsed() { 13 | struct timespec ts; 14 | clock_gettime(CLOCK_REALTIME, &ts); 15 | if (ts.tv_nsec < t0.tv_nsec) { 16 | ts.tv_nsec = 1000000000 + ts.tv_nsec - t0.tv_nsec; 17 | ts.tv_sec--; 18 | } 19 | ts.tv_sec -= t0.tv_sec; 20 | return (ts); 21 | } 22 | 23 | int timelog(const char* message) { 24 | struct timespec ts = elapsed(); 25 | return (printf("[%06ld.%09ld] %s\n", ts.tv_sec, ts.tv_nsec, message)); 26 | } 27 | 28 | void * malloc_double_align(size_t n, unsigned int a /*alignment*/, double * &output) { 29 | void *adres = NULL; 30 | void *adres2 = NULL; 31 | adres = malloc(n * sizeof(double) + a); 32 | size_t adr = (size_t) adres; 33 | size_t adr2 = adr + a - (adr & (a - 1u)); // a valid address for a alignment 34 | adres2 = reinterpret_cast(adr2); 35 | output = reinterpret_cast(adres2); 36 | return adres; // pointer to be used in free() 37 | } 38 | 39 | void print_timenl() { 40 | clock_t c = clock(); 41 | double t = static_cast(c) / CLOCKS_PER_SEC; 42 | std::cout << "Time = " << t << std::endl; 43 | } 44 | 45 | void print_time() { 46 | clock_t c = clock(); 47 | double t = static_cast(c) / CLOCKS_PER_SEC; 48 | std::cout << "Time = " << t << " : "; 49 | } 50 | 51 | #endif // PROPCA_HELPER_H_ 52 | -------------------------------------------------------------------------------- /include/matmult.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPCA_MATMULT_H_ 2 | #define PROPCA_MATMULT_H_ 3 | 4 | 5 | #include "genotype.h" 6 | 7 | class MatMult { 8 | public: 9 | Genotype g; 10 | MatrixXdr geno_matrix; // (p,n) 11 | 12 | bool debug; // = false; 13 | bool var_normalize; // = false; 14 | bool memory_efficient; // = false; 15 | bool missing; // = false; 16 | bool fast_mode; // = true; 17 | int nthreads; // = 1; 18 | 19 | // How to batch columns: 20 | int blocksize; // k 21 | int hsegsize; // = log_3(n) 22 | int hsize; 23 | int vsegsize; // = log_3(p) 24 | int vsize; 25 | 26 | double **partialsums; 27 | double *sum_op; 28 | 29 | // Intermediate computations in E-step. 30 | double **yint_e; // Size = 3^(log_3(n)) * k 31 | double ***y_e; // n X k 32 | 33 | // Intermediate computations in M-step. 34 | double **yint_m; // Size = nthreads X 3^(log_3(n)) * k 35 | double ***y_m; // nthreads X log_3(n) X k 36 | 37 | MatMult() {} 38 | 39 | MatMult(Genotype &xg, 40 | MatrixXdr &xgeno_matrix, 41 | bool xdebug, 42 | bool xvar_normalize, 43 | bool xmemory_efficient, 44 | bool xmissing, 45 | bool xfast_mode, 46 | int xnthreads, 47 | int xk); 48 | 49 | void multiply_y_pre_fast_thread(int begin, int end, MatrixXdr &op, int Ncol_op, double *yint_m, double **y_m, double *partialsums, MatrixXdr &res); 50 | void multiply_y_post_fast_thread(int begin, int end, MatrixXdr &op, int Ncol_op, double *yint_e, double **y_e, double *partialsums); 51 | 52 | /* 53 | * M-step: Compute C = Y E 54 | * Y : p X n genotype matrix 55 | * E : n K k matrix: X^{T} (XX^{T})^{-1} 56 | * C = p X k matrix 57 | * 58 | * op : E 59 | * Ncol_op : k 60 | * res : C 61 | * subtract_means : 62 | */ 63 | void multiply_y_pre_fast(MatrixXdr &op, int Ncol_op, MatrixXdr &res, bool subtract_means); 64 | 65 | /* 66 | * E-step: Compute X = D Y 67 | * Y : p X n genotype matrix 68 | * D : k X p matrix: (C^T C)^{-1} C^{T} 69 | * X : k X n matrix 70 | * 71 | * op_orig : D 72 | * Nrows_op : k 73 | * res : X 74 | * subtract_means : 75 | */ 76 | void multiply_y_post_fast(MatrixXdr &op_orig, int Nrows_op, MatrixXdr &res, bool subtract_means); 77 | void multiply_y_pre_naive_mem(MatrixXdr &op, int Ncol_op, MatrixXdr &res); 78 | void multiply_y_post_naive_mem(MatrixXdr &op, int Nrows_op, MatrixXdr &res); 79 | 80 | void multiply_y_post(MatrixXdr &op, int Nrows_op, MatrixXdr &res, bool subtract_means); 81 | 82 | void multiply_y_pre(MatrixXdr &op, int Ncol_op, MatrixXdr &res, bool subtract_means); 83 | 84 | void clean_up(); 85 | }; 86 | 87 | 88 | #endif // PROPCA_MATMULT_H_ 89 | -------------------------------------------------------------------------------- /include/storage.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPCA_STORAGE_H_ 2 | #define PROPCA_STORAGE_H_ 3 | 4 | 5 | #include 6 | 7 | 8 | void add_to_arr(int x, int j, int beta, std::vector &arr); 9 | 10 | int extract_from_arr(int j, int beta, std::vector &arr); 11 | 12 | std::vector get_orig_arr(int beta, std::vector &arr, int Nelements); 13 | 14 | #endif // PROPCA_STORAGE_H_ 15 | -------------------------------------------------------------------------------- /misc/assessment/README.md: -------------------------------------------------------------------------------- 1 | ### Contents 2 | 3 | + `metrics.R` contains several of the functions used to evaluate results 4 | + `visualize.R` contains an example for visualizing our results 5 | 6 | #### Metrics 7 | 8 | The `metrics.R` file can be loaded in using the `source` function in R. We include our functions to perform permutation matching and calculate several metrics (root-mean-square-error, Jensen-Shannon divergence, Kullback-Leibler divergence). Our script utilizes the [lpSolve](https://CRAN.R-project.org/package=lpSolve) package and will be needed to utilize this script. 9 | 10 | #### Visualization 11 | 12 | The script `visualize.R` is an example for how we visualized our results in our manuscript. Currently, it will use the truth and outputs from the `examples` subdirectory from the root. You may need to modify the paths to the example files in the script if you have changed or moved them to properly run the script. Our visualization script utilizes `metrics.R` (included in this directory), [RColorBrewer](https://CRAN.R-project.org/package=RColorBrewer), [data.table](https://CRAN.R-project.org/package=data.table), and [genieclust](https://CRAN.R-project.org/package=genieclust). We do not require genieclust, but we suggest it be used when using our visualization script for large datasets. 13 | 14 | -------------------------------------------------------------------------------- /misc/assessment/example_viz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sriramlab/SCOPE/e09c6546c67915f87d9aaf2581fbb300ad9c47a3/misc/assessment/example_viz.png -------------------------------------------------------------------------------- /misc/assessment/metrics.R: -------------------------------------------------------------------------------- 1 | #!/bin/env Rscript 2 | 3 | require(lpSolve) 4 | 5 | PongDist <- function(x,y,K){ 6 | thresh <- 0.1/K 7 | arr <- x-y 8 | arr2 <- which(x+y > thresh) 9 | arr <- arr[arr2] 10 | return(1 - sqrt(sum(arr^2) / (2*length(arr)))) 11 | } 12 | 13 | PongMatch <- function(Theta_true,Theta){ 14 | # Matches Theta to Theta_true 15 | # Returns reordered version of Theta 16 | dist_mat <- apply(Theta_true,2,function(x){apply(Theta,2,function(y){PongDist(x,y,K=ncol(Theta))})}) 17 | col_ord <- apply(lp.assign(dist_mat, direction = "max")$solution,2,which.max) 18 | return(Theta[,col_ord]) 19 | } 20 | 21 | MAE <- function(Theta_true,Theta){ 22 | # Function to calculate MAE 23 | Theta_permute <- PongMatch(Theta_true,Theta) 24 | err <- median(apply(abs((as.matrix(Theta_true)-as.matrix(Theta_permute))),1,median)) 25 | return(err) 26 | } 27 | 28 | ErrMinPerm <- function(Theta_true,Theta){ 29 | # Function to calculate RMSE 30 | Theta_permute <- PongMatch(Theta_true,Theta) 31 | err <- norm(as.matrix(Theta_true) - as.matrix(Theta_permute),'F') / sqrt(nrow(Theta)*ncol(Theta)) 32 | return(err) 33 | } 34 | 35 | JSD <- function(Theta_true,Theta_unmatched,eps=1e-9){ 36 | # Calculates Jensen-Shannon Divergence 37 | Theta <- PongMatch(Theta_true,Theta_unmatched) 38 | Theta_true2 <- Theta_true 39 | Theta2 <- Theta 40 | if (any(Theta_true2 == 0)){ 41 | Theta_true2[Theta_true2 == 0] <- eps 42 | Theta_true2 <- t(apply(Theta_true2,1,function(x){x/sum(x)})) 43 | } 44 | if (any(Theta2 == 0)){ 45 | Theta2[Theta2 == 0] <- eps 46 | Theta2 <- t(apply(Theta2,1,function(x){x/sum(x)})) 47 | } 48 | M <- 0.5 * (Theta_true2 + Theta2) 49 | KL_mat1 <- t(sapply(1:nrow(Theta_true2),function(i){as.numeric(Theta_true2[i,]*log(Theta_true2[i,]/M[i,]))})) 50 | KL_mat2 <- t(sapply(1:nrow(Theta2),function(i){as.numeric(Theta2[i,]*log(Theta2[i,]/M[i,]))})) 51 | KL_mat <- (KL_mat1 + KL_mat2) * 0.5 52 | return(mean(rowSums(KL_mat*is.finite(KL_mat),na.rm = T))) 53 | } 54 | 55 | KL <- function(Theta_true,Theta,eps=1e-9){ 56 | # Calculate KL Divergence 57 | Theta_true2 <- Theta_true 58 | Theta2 <- PongMatch(Theta_true,Theta) 59 | if (any(Theta_true2 == 0)){ 60 | Theta_true2[Theta_true2 == 0] <- eps 61 | Theta_true2 <- t(apply(Theta_true2,1,function(x){x/sum(x)})) 62 | } 63 | if (any(Theta2 == 0)){ 64 | Theta2[Theta2 == 0] <- eps 65 | Theta2 <- t(apply(Theta2,1,function(x){x/sum(x)})) 66 | } 67 | KL_mat <- t(sapply(1:nrow(Theta_true2),function(i){as.numeric(Theta_true2[i,]*log(Theta_true2[i,]/Theta2[i,]))})) 68 | return(mean(rowSums(KL_mat*is.finite(KL_mat),na.rm = T))) 69 | } 70 | 71 | CalculateMetrics <- function(Theta_true,Theta){ 72 | # Function to calculate metrics 73 | theta_permute <- Theta 74 | kld <- KL(Theta_true,theta_permute) 75 | jsd <- JSD(Theta_true,theta_permute) 76 | rmse <- ErrMinPerm(Theta_true,Theta) 77 | metrics <- c(kld,jsd,rmse) 78 | names(metrics) <- c("KL","JSD","RMSE") 79 | return(metrics) 80 | } 81 | 82 | -------------------------------------------------------------------------------- /misc/assessment/visualize.R: -------------------------------------------------------------------------------- 1 | #!/bin/env Rscript 2 | 3 | library(RColorBrewer) 4 | library(data.table) 5 | source('metrics.R') 6 | #library(genieclust) 7 | 8 | set.seed(1) 9 | 10 | png("example.png",units = "in",height=8.5,width=11,res=330) 11 | par(mfrow=c(3,1),mai=c(0.1,0.1,0.2,0.1)) 12 | 13 | ## Replace the arguments to the 'fread' function 14 | 15 | truth <- fread("../../examples/source_files/example_1k_proportions.txt",data.table = F) 16 | ordering <- hclust(dist(truth))$order # Replace with gclust for scalablity 17 | colIS <- brewer.pal(ncol(truth), "Paired") 18 | barplot(t(truth[ordering,]), col=colIS, border=NA, space=0, axes=F,axisnames = F,main="Truth") 19 | 20 | scope <- PongMatch(truth,t(fread("../../examples/results/unsupervised/unsupervised_example_1k_Qhat.txt",data.table=F))) 21 | barplot(t(scope[ordering,]), col=colIS, border=NA, space=0,axes=F,axisnames = F,main="Unsupervised SCOPE") 22 | 23 | scope <- PongMatch(truth,t(fread("../../examples/results/supervised/supervised_example_1k_Qhat.txt",data.table=F))) 24 | barplot(t(scope[ordering,]), col=colIS, border=NA, space=0,axes=F,axisnames = F,main="Supervised SCOPE") 25 | 26 | dev.off() 27 | -------------------------------------------------------------------------------- /misc/real_data/HGDP/get_HGDP.sh: -------------------------------------------------------------------------------- 1 | 2 | # Get HGDP 3 | wget https://hagsc.org/hgdp/data/hgdp.zip 4 | unzip hgdp.zip 5 | mv hgdp/* . 6 | rm -rf __MACOSX 7 | rmdir hgdp 8 | 9 | # Get Sample Information 10 | wget http://rosenberglab.stanford.edu/data/rosenberg2006ahg/SampleInformation.txt 11 | 12 | # Remove column sums 13 | head -n -1 SampleInformation.txt > SampleInformation2.txt 14 | mv SampleInformation2.txt SampleInformation.txt 15 | 16 | # Convert to MAP/PED 17 | python HGDP_text_to_tped.py 18 | 19 | # Convert to PLINK BED/BIM/FAM 20 | plink --tfile HGDP_940 --make-bed --out HGDP_940 21 | 22 | # Calculate HGDP frequencies 23 | plink --bfile HGDP_940 --freq --out HGDP_940 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /misc/real_data/HGDP/hgdp_param.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sriramlab/SCOPE/e09c6546c67915f87d9aaf2581fbb300ad9c47a3/misc/real_data/HGDP/hgdp_param.txt.gz -------------------------------------------------------------------------------- /misc/real_data/HO/convertf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sriramlab/SCOPE/e09c6546c67915f87d9aaf2581fbb300ad9c47a3/misc/real_data/HO/convertf -------------------------------------------------------------------------------- /misc/real_data/HO/ho_remove.samps: -------------------------------------------------------------------------------- 1 | 937 Chimp 2 | 938 Denisova_light 3 | 939 Vindija_light 4 | 940 Href 5 | 941 Gorilla 6 | 942 Orang 7 | 943 Macaque 8 | 944 Marmoset 9 | 990 AD_066 10 | 992 AD_064 11 | 993 AD_505 12 | 996 AD_523 13 | 997 AD_500 14 | 1000 AD_510 15 | 1001 AD_015 16 | 1004 AD_061 17 | 1006 AD_076 18 | 1007 AD_512 19 | 1008 AD_006 20 | 1009 AD_511 21 | 1950 Altai 22 | 1951 Denisova 23 | 1952 Loschbour 24 | 1953 LBK380 25 | 1954 Mez1 26 | 1955 Otzi 27 | 1957 MA1 28 | 1958 AG2 29 | 1959 Skoglund_HG 30 | 1960 Skoglund_farmer 31 | 1961 Motala_merge 32 | 1962 Motala12 33 | -------------------------------------------------------------------------------- /misc/real_data/HO/prepare_ho.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | # Download HO 4 | wget https://reich.hms.harvard.edu/sites/reich.hms.harvard.edu/files/inline-files/EuropeFullyPublic.tar.gz 5 | tar -xvzf EuropeFullyPublic.tar.gz 6 | mv EuropeFullyPublic/data.* . 7 | rm -r EuropeFullyPublic 8 | 9 | # Convert to PLINK BED/BIM/FAM using EIGENSOFT 10 | touch ho_plink.convertf_par 11 | 12 | echo "genotypename: data.geno" >> ho_plink.convertf_par 13 | echo "snpname: data.snp" >> ho_plink.convertf_par 14 | echo "indivname: data.ind" >> ho_plink.convertf_par 15 | echo "outputformat: PACKEDPED" >> ho_plink.convertf_par 16 | echo "genooutfilename: ho.bed" >> ho_plink.convertf_par 17 | echo "snpoutfilename: ho.bim" >> ho_plink.convertf_par 18 | echo "indoutfilename: ho.fam" >> ho_plink.convertf_par 19 | 20 | convertf -p ho_plink.convertf_par 21 | awk '{if ($1 == 90) print "c"$0; else print $0}' ho.bim > ho2.bim 22 | rm ho.bim 23 | mv ho2.bim ho.bim 24 | 25 | # Create final HO BED/BIM/FAM with filters 26 | plink --bfile ho --remove ../ho_remove.samps --geno 0.01 --maf 0.05 --allow-extra-chr --make-bed --out ho_final --chr 1-26 27 | 28 | -------------------------------------------------------------------------------- /misc/real_data/README.md: -------------------------------------------------------------------------------- 1 | ## Real Datasets 2 | 3 | We have included several scripts to regenerate the real datasets and parameters used in our manuscript. 4 | 5 | ### HGDP 6 | 7 | This subdirectory contains a script to generate the Human Genome Diversity Project (HGDP) dataset. We also include `hgdp_param.txt.gz`, which is the parameter file used in our manuscript that can be given as input to our simulation scripts found in `misc/simulations` from the root of the repository. 8 | 9 | ### HO 10 | 11 | This subdirectory contains a script to generate the Human Origins (HO) dataset. We have included `ho_remove.samps`, which contains manually curated samples to be removed (_e.g._ non-human samples). We also include a binary,`convertrf`, from the [EIGENSOFT suite](https://www.hsph.harvard.edu/alkes-price/software/) for converting the EIGENSTRAT format. 12 | 13 | ### TGP 14 | 15 | This subdirectory contains a script to generate the 1000 Genomes Project (TGP) dataset. The script, `get_tgp.sh`, will download and convert the data to a PLINK binary fileset. The script, `gen_tgp_plink_metrics.sh`, will generate frequencies and FST values based on population and superpopulation labels found in `tgp_pops.txt` and `tgp_super_pops.txt`, respectively. It will also generate the parameter files used by our simulations scripts found in `misc/simulations`. `TGP_unrel.txt` contains a manually curated list of unrelated individuals curated by the authors of [TeraStructure](https://github.com/StoreyLab/terastructure). 16 | 17 | ### UKB 18 | 19 | This subdirectory contains a script to process the UK Biobank (UKB) dataset. The UKB dataset is not publicly available, so users will need to edit the script to specify the location of their UKB PLINK binary files for the array data. We also include `long_range_ld.filter`, which lists several SNPs involved in long-range linkage disequilibrium. 20 | 21 | ### Acknowledgements 22 | 23 | We would like to acknowledge the authors of TeraStructure for providing [starter scripts](https://github.com/StoreyLab/terastructure/tree/master/scripts/data) for us in preparing these datasets. 24 | 25 | -------------------------------------------------------------------------------- /misc/real_data/TGP/gen_tgp_plink_metrics.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | # Calculate frequencies and get FST 4 | plink --bfile TGP_1718 --freq --out tgp_freqs 5 | plink --bfile TGP_1718 --fst --within tgp_pops.txt --out tgp_pops 6 | plink --bfile TGP_1718 --fst --within tgp_super_pops.txt --out tgp_super_pops 7 | 8 | # Generate parameter files for simulation scripts 9 | awk '{print $5}' tgp_super_pops.fst | paste tgp_freqs.frq - > tgp_superpop_param.txt 10 | awk '{print $5}' tgp_pops.fst | paste tgp_freqs.frq - > tgp_pop_param.txt 11 | -------------------------------------------------------------------------------- /misc/real_data/TGP/get_tgp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | # Download TGP 4 | wget ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/working/20120131_omni_genotypes_and_intensities/Omni25_genotypes_2141_samples.b37.vcf.gz 5 | 6 | # Convert to PLINK format, remove related individuals, MAF filter 7 | vcftools --gzvcf Omni25_genotypes_2141_samples.b37.vcf.gz --keep TGP_unrel.txt --maf 0.01 --max-missing 0.95 --max-alleles 2 --min-alleles 2 --chr 1 --chr 2 --chr 3 --chr 4 --chr 5 --chr 6 --chr 7 --chr 8 --chr 9 --chr 10 --chr 11 --chr 12 --chr 13 --chr 14 --chr 15 --chr 16 --chr 17 --chr 18 --chr 19 --chr 20 --chr 21 --chr 22 --plink-tped --out TGP_plink 8 | 9 | # Convert to PLINK BED/BIM/FAM 10 | plink --tfile TGP_plink --make-bed --out TGP_1718 11 | 12 | -------------------------------------------------------------------------------- /misc/real_data/UKB/prepare_ukb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | ukb_prefix="" 4 | 5 | # MAF Filter 6 | plink --bfile $ukb_prefix --maf 0.01 --make-bed --out maf_01 7 | 8 | # LD Pruning 9 | plink --bfile maf_01 --indep-pairwise 50 kb 80 0.1 10 | plink --bfile maf_01 --extract plink.prune.in --make-bed --out pruned_ukb 11 | 12 | # Long-range LD removal 13 | plink --bfile pruned_ukb --exclude long_range_ld.filter --make-bed --out ukb_no_long_ld 14 | 15 | -------------------------------------------------------------------------------- /misc/simulations/README.md: -------------------------------------------------------------------------------- 1 | ## Simulation Scripts 2 | 3 | We provide our simulation scripts used in our manuscript. We require the following packages: 4 | 5 | + [numpy](https://numpy.org/) 6 | + [pyplink](https://lemieuxl.github.io/pyplink/) 7 | + [scipy](https://www.scipy.org/) 8 | + [parmapper](https://github.com/Jwink3101/parmapper) 9 | 10 | The script `install_packages.sh` will install `pyplink` and `parmapper`. The script `generate_simulations_python.sh` will generate several of the simulations utilized in our manuscript. The parameter files and how to create them can be found in `misc/real_data` from the root directory. Do **not** blindly run `generate_simulations_python.sh` as several of the generated datasets are very large and can easily exhaust computational resources. 11 | 12 | ### Simulation Scripts 13 | 14 | We provide the simulation scripts for both scenarios used in our manuscript. The script `simulateA.py` generates simulation under the [Pritchard-Stephens-Donneley (PSD) model](https://www.genetics.org/content/155/2/945). See `python simulateA.py --help` for additional information. Please note that the parameter file (`freq_fst_file` argument) is non-standard. It is the last column of the output from `plink --fst` appended to the end of the output of `plink --freq`. Please see the scripts and files in `misc/real_data` to generate the TGP and HGDP parameter files we used in our manuscript. 15 | 16 | The other script `simulateB.py` generates simulations under a spatial model as described in [Ochoa and Storey 2020](https://doi.org/10.1371/journal.pgen.1009241). Please see the [Ochoa and Storey 2020](https://doi.org/10.1371/journal.pgen.1009241) or our manuscript for more details. This script requires similar arugments as our other simulation script, but has a few differences, which can be found by running `python simulateB.py --help`. 17 | 18 | ### PLINK Conversion Script 19 | 20 | SCOPE can take the output from `plink --freq` as input to perform supervised analysis. The script `generate_plink_frq.py` will convert output from previous SCOPE runs to match the output from `plink --freq`. It requires the path to the PLINK BIM file, the outputted frequencies, and the output filename as input. 21 | 22 | -------------------------------------------------------------------------------- /misc/simulations/generate_plink_frq.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | 7 | if len(sys.argv) != 4: 8 | print("Usage: python3 generate_plink_frq.py plink_bim true_freqs outfile",file=sys.stderr) 9 | exit(1) 10 | 11 | outfile = open(sys.argv[3],'w+') 12 | bim_file = open(sys.argv[1],'r+') 13 | freqs_file = open(sys.argv[2],'r+') 14 | 15 | bim = bim_file.readlines() 16 | freqs = freqs_file.readlines() 17 | 18 | bim_file.close() 19 | freqs_file.close() 20 | 21 | outfile.write("CHR\tSNP\tCLST\tA1\tA2\tMAF\tMAC\tNCHROBS\n") 22 | 23 | for i in range(len(bim)): 24 | line = bim[i].rstrip().strip().split() 25 | CHR = line[0] 26 | SNP = line[1] 27 | A1 = line[4] 28 | A2 = line[5] 29 | snp_freq = freqs[i].rstrip().strip().split() 30 | for j in range(len(snp_freq)): 31 | outfile.write("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(CHR,SNP,j+1,A1,A2,snp_freq[j],"N","N")) 32 | 33 | outfile.close() 34 | 35 | exit(0) 36 | -------------------------------------------------------------------------------- /misc/simulations/generate_simulations_python.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | echo Run \"bash install_packages.sh\" once before running simulations 4 | echo --------------------------- 5 | 6 | mkdir simulationA 7 | mkdir simulationB 8 | 9 | python3 simulateA.py -np 6 -c 100000 10000 1000000 tgp_superpop_param.txt simulationA/n10k_1m_snps 10 | python3 simulateA.py -np 6 -c 100000 100000 1000000 tgp_superpop_param.txt simulationA/n100k_1m_snps 11 | python3 simulateA.py -np 6 -c 10000 1000000 1000000 tgp_superpop_param.txt simulationA/n1m_1m_snps 12 | 13 | python3 simulateB.py -np 6 -c 100000 10000 100000 tgp_superpop_param.txt simulationB/n10k_100k_snps 14 | python3 simulateB.py -np 6 -c 100000 10000 1000000 tgp_superpop_param.txt simulationB/n10k_1m_snps 15 | 16 | python3 simulateA.py -np 6 -c 10000 1000000 1000000 tgp_superpop_param.txt simulationA/n1m_1m_snps 17 | 18 | -------------------------------------------------------------------------------- /misc/simulations/install_packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/env bash 2 | 3 | pip install pyplink 4 | pip install git+https://github.com/Jwink3101/parmapper 5 | -------------------------------------------------------------------------------- /src/run_alstructure.cpp: -------------------------------------------------------------------------------- 1 | #include "alstructure.h" 2 | 3 | 4 | int main(int argc, char const *argv[]) { 5 | ALStructure A = ALStructure(argc, argv); 6 | return A.run(); 7 | } 8 | -------------------------------------------------------------------------------- /src/storage.cpp: -------------------------------------------------------------------------------- 1 | #include "storage.h" 2 | 3 | 4 | void add_to_arr(int x, int j, int beta, std::vector &arr) { 5 | unsigned temp = j * beta; 6 | unsigned idx = (temp) >> 5; 7 | unsigned rem = temp & (0x0000001F); 8 | unsigned add = rem + beta; 9 | 10 | if (add > 32) { 11 | arr[idx] = arr[idx] & ( ((1 << rem) - 1) << (32-rem) ); 12 | arr[idx] = arr[idx] | (x >> (add-32)); 13 | arr[idx+1] = (x << (64-add)) | (arr[idx+1] & ((1<<64-add) - 1)); 14 | } else { 15 | unsigned mask_left, mask_right; 16 | mask_left = ((1 << rem) - 1) << (32-rem); 17 | mask_right = (1 << (32-add)) -1; 18 | arr[idx] = (arr[idx] & mask_left) | (arr[idx] & mask_right); 19 | arr[idx] = arr[idx] | (x << (32-add)); 20 | } 21 | } 22 | 23 | 24 | int extract_from_arr(int j, int beta, std::vector &arr) { 25 | unsigned temp = j * beta; 26 | unsigned idx = (temp) >> 5; 27 | unsigned rem = temp & (0x0000001F); 28 | 29 | int res = 0; 30 | unsigned add = rem + beta; 31 | 32 | if (add > 32) { 33 | unsigned mask = 0; 34 | mask = (1 << (32-rem)) - 1; 35 | 36 | int lastXbits = arr[idx] & mask; 37 | 38 | res = (lastXbits << (add-32)) | (arr[idx+1] >> (64-add)); 39 | } else { 40 | res = (arr[idx] << rem) >> (32-beta); 41 | } 42 | 43 | return res; 44 | } 45 | 46 | std::vector get_orig_arr(int beta, std::vector &arr, int Nelements) { 47 | std::vector v; 48 | for (int i = 0; i < Nelements; i++) { 49 | int temp = extract_from_arr(i, beta, arr); 50 | v.push_back(temp); 51 | } 52 | return v; 53 | } 54 | --------------------------------------------------------------------------------