├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── pytorch_ctc ├── __init__.py └── src │ ├── cpu_binding.cpp │ ├── cpu_binding.h │ ├── ctc_beam_entry.h │ ├── ctc_beam_scorer.h │ ├── ctc_beam_scorer_klm.h │ ├── ctc_beam_search.h │ ├── ctc_decoder.h │ ├── ctc_labels.h │ ├── ctc_loss_util.h │ ├── ctc_trie_node.h │ └── util │ ├── macros.h │ ├── status.cpp │ ├── status.h │ └── top_n.h ├── requirements.txt ├── setup.py ├── tests └── test.py └── third_party ├── eigen3 └── Eigen │ ├── Core │ └── src │ ├── 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 │ └── plugins │ ├── ArrayCwiseBinaryOps.h │ ├── ArrayCwiseUnaryOps.h │ ├── BlockMethods.h │ ├── CommonCwiseBinaryOps.h │ ├── CommonCwiseUnaryOps.h │ ├── MatrixCwiseBinaryOps.h │ └── MatrixCwiseUnaryOps.h └── utf8 ├── utf8.h └── utf8 ├── checked.h ├── core.h └── unchecked.h /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | _ext 3 | ctc_decode 4 | *.pyc 5 | 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *.cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # Environments 87 | .env 88 | .venv 89 | env/ 90 | venv/ 91 | ENV/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | # Prerequisites 107 | *.d 108 | 109 | # Compiled Object files 110 | *.slo 111 | *.lo 112 | *.o 113 | *.obj 114 | 115 | # Precompiled Headers 116 | *.gch 117 | *.pch 118 | 119 | # Compiled Dynamic libraries 120 | *.so 121 | *.dylib 122 | *.dll 123 | 124 | # Fortran module files 125 | *.mod 126 | *.smod 127 | 128 | # Compiled Static libraries 129 | *.lai 130 | *.la 131 | *.a 132 | *.lib 133 | 134 | # Executables 135 | *.exe 136 | *.out 137 | *.app 138 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pytorch_ctc/src/third_party/kenlm"] 2 | path = third_party/kenlm 3 | url = https://github.com/kpu/kenlm.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ryan Leary 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 | # pytorch-ctc 2 | PyTorch-CTC is an implementation of CTC (Connectionist Temporal Classification) beam search decoding for PyTorch. C++ code borrowed liberally from TensorFlow with some improvements to increase flexibility. 3 | 4 | ## Installation 5 | The library is largely self-contained and requires only PyTorch and CFFI. Building the C++ library requires at least GCC-5. If gcc-5 or later is not your default compiler, you may specify the path via environment variables. KenLM language modeling support is also optionally included, and enabled by default. 6 | 7 | ```bash 8 | # get the code 9 | git clone --recursive https://github.com/ryanleary/pytorch-ctc.git 10 | cd pytorch-ctc 11 | 12 | # install dependencies (PyTorch and CFFI) 13 | pip install -r requirements.txt 14 | 15 | # build the extension and install python package (requires gcc-5 or later) 16 | # python setup.py install 17 | CC=/path/to/gcc-5 CXX=/path/to/g++-5 python setup.py install 18 | 19 | # If you do NOT require kenlm, the `--recursive` flag is not required on git clone 20 | # and `--exclude-kenlm` should be appended to the `python setup.py install` command 21 | ``` 22 | 23 | ## API 24 | pytorch-ctc includes a CTC beam search decoder with multiple scorer implementations. A `scorer` is a function that the decoder calls to condition the probability of a given beam based on its state. 25 | 26 | ### Scorers 27 | Two Scorer implementations are currently implemented for pytorch-ctc. 28 | 29 | **Scorer:** is a NO-OP and enables the decoder to do a vanilla beam decode 30 | ```python 31 | scorer = Scorer() 32 | ``` 33 | 34 | **KenLMScorer:** conditions beams based on the provided KenLM binary language model. 35 | ```python 36 | scorer = KenLMScorer(labels, lm_path, trie_path, blank_index=0, space_index=28) 37 | ``` 38 | 39 | where: 40 | - `labels` is a string of output labels given in the same order as the output layer 41 | - `lm_path` path to a binary KenLM language model for decoding 42 | - `trie_path` path to a Trie containing the lexicon (see generate_lm_trie) 43 | - `blank_index` is used to specify which position in the output distribution represents the `blank` class 44 | - `space_index` is used to specify which position in the output distribution represents the word separator class 45 | 46 | The `KenLMScorer` may be further configured with weights for the language model contribution to the score (`lm_weight`), as well as word and valid word bonuses (to offset decreasing probability as a function of sequence length). 47 | 48 | ```python 49 | scorer.set_lm_weight(2.1) 50 | scorer.set_word_weight(1.1) 51 | scorer.set_valid_word_weight(1.5) 52 | ``` 53 | 54 | ### Decoder 55 | ```python 56 | decoder = CTCBeamDecoder(scorer, labels, top_paths=3, beam_width=20, 57 | blank_index=0, space_index=28, merge_repeated=False) 58 | ``` 59 | 60 | where: 61 | - `scorer` is an instance of a concrete implementation of the `BaseScorer` class 62 | - `labels` is a string of output labels given in the same order as the output layer 63 | - `top_paths` is used to specify how many hypotheses to return 64 | - `beam_width` is the number of beams to evaluate in a given step 65 | - `blank_index` is used to specify which position in the output distribution represents the `blank` class 66 | - `space_index` is used to specify which position in the output distribution represents the word separator class 67 | - `merge_repeated` if True will collapse repeated characters 68 | 69 | ```python 70 | output, score, out_seq_len = decoder.decode(probs, sizes=None) 71 | ``` 72 | 73 | where: 74 | - `probs` is a FloatTensor of log-probabilities with shape `(seq_len, batch_size, num_classes)` 75 | - `seq_len` is an optional IntTensor of integer sequence lengths with shape `(batch_size)` 76 | 77 | and returns: 78 | - `output` is an IntTensor of character classes of shape `(top_paths, batch_size, seq_len)` 79 | - `score` is a FloatTensor of log-probabilities representing the likelihood of the transcription with shape `(top_paths, batch_size)` 80 | - `out_seq_len` is an IntTensor containing the length of the output sequence with shape `(top_paths, batch_size)` 81 | 82 | ### Utilities 83 | ```python 84 | generate_lm_trie(dictionary_path, kenlm_path, output_path, labels, blank_index, space_index) 85 | ``` 86 | 87 | A vocabulary trie is required for the KenLM Scorer. The trie is created from a lexicon specified as a newline separated text file of words in the vocabulary. 88 | 89 | ## Acknowledgements 90 | Thanks to [ebrevdo](https://github.com/ebrevdo) for the original TensorFlow CTC decoder implementation, [timediv](https://github.com/timediv) for his KenLM extension, and [SeanNaren](https://github.com/seannaren) for his assistance. 91 | -------------------------------------------------------------------------------- /pytorch_ctc/__init__.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import pytorch_ctc as ctc 3 | from torch.utils.ffi import _wrap_function 4 | from ._ctc_decode import lib as _lib, ffi as _ffi 5 | 6 | __all__ = [] 7 | 8 | 9 | def _import_symbols(locals): 10 | for symbol in dir(_lib): 11 | fn = getattr(_lib, symbol) 12 | new_symbol = "_" + symbol 13 | locals[new_symbol] = _wrap_function(fn, _ffi) 14 | __all__.append(new_symbol) 15 | 16 | 17 | _import_symbols(locals()) 18 | 19 | 20 | class BaseCTCBeamDecoder(object): 21 | def __init__(self, labels, top_paths=1, beam_width=10, blank_index=0, space_index=28, merge_repeated=True): 22 | self._labels = labels 23 | self._top_paths = top_paths 24 | self._beam_width = beam_width 25 | self._blank_index = blank_index 26 | self._space_index = space_index 27 | self._merge_repeated = merge_repeated 28 | self._num_classes = len(labels) 29 | self._decoder = None 30 | 31 | if blank_index < 0 or blank_index >= self._num_classes: 32 | raise ValueError("blank_index must be within num_classes") 33 | 34 | if top_paths < 1 or top_paths > beam_width: 35 | raise ValueError("top_paths must be greater than 1 and less than or equal to the beam_width") 36 | 37 | def decode(self, probs, seq_len=None): 38 | prob_size = probs.size() 39 | max_seq_len = prob_size[0] 40 | batch_size = prob_size[1] 41 | num_classes = prob_size[2] 42 | 43 | if seq_len is not None and batch_size != seq_len.size(0): 44 | raise ValueError("seq_len shape must be a (batch_size) tensor or None") 45 | 46 | seq_len = torch.IntTensor(batch_size).zero_().add_(max_seq_len) if seq_len is None else seq_len 47 | output = torch.IntTensor(self._top_paths, batch_size, max_seq_len) 48 | scores = torch.FloatTensor(self._top_paths, batch_size) 49 | out_seq_len = torch.IntTensor(self._top_paths, batch_size) 50 | 51 | result = ctc._ctc_beam_decode(self._decoder, self._decoder_type, probs, seq_len, output, scores, out_seq_len) 52 | 53 | return output, scores, out_seq_len 54 | 55 | 56 | class BaseScorer(object): 57 | def __init__(self): 58 | self._scorer_type = 0 59 | self._scorer = None 60 | 61 | def get_scorer_type(self): 62 | return self._scorer_type 63 | 64 | def get_scorer(self): 65 | return self._scorer 66 | 67 | 68 | class Scorer(BaseScorer): 69 | def __init__(self): 70 | super(Scorer, self).__init__() 71 | self._scorer = ctc._get_base_scorer() 72 | 73 | 74 | class KenLMScorer(BaseScorer): 75 | def __init__(self, labels, lm_path, trie_path, blank_index=0, space_index=28): 76 | super(KenLMScorer, self).__init__() 77 | if ctc._kenlm_enabled() != 1: 78 | raise ImportError("pytorch-ctc not compiled with KenLM support.") 79 | self._scorer_type = 1 80 | self._scorer = ctc._get_kenlm_scorer(labels, len(labels), space_index, blank_index, lm_path.encode(), trie_path.encode()) 81 | 82 | def set_lm_weight(self, weight): 83 | if weight is not None: 84 | ctc._set_kenlm_scorer_lm_weight(self._scorer, weight) 85 | 86 | def set_word_weight(self, weight): 87 | if weight is not None: 88 | ctc._set_kenlm_scorer_wc_weight(self._scorer, weight) 89 | 90 | def set_valid_word_weight(self, weight): 91 | if weight is not None: 92 | ctc._set_kenlm_scorer_vwc_weight(self._scorer, weight) 93 | 94 | 95 | class CTCBeamDecoder(BaseCTCBeamDecoder): 96 | def __init__(self, scorer, labels, top_paths=1, beam_width=10, blank_index=0, space_index=28, merge_repeated=True): 97 | super(CTCBeamDecoder, self).__init__(labels, top_paths=top_paths, beam_width=beam_width, blank_index=blank_index, space_index=space_index, merge_repeated=merge_repeated) 98 | merge_int = 1 if merge_repeated else 0 99 | self._scorer = scorer 100 | self._decoder_type = self._scorer.get_scorer_type() 101 | self._decoder = ctc._get_ctc_beam_decoder(self._num_classes, top_paths, beam_width, blank_index, merge_int, self._scorer.get_scorer(), self._decoder_type) 102 | 103 | 104 | def generate_lm_trie(dictionary_path, kenlm_path, output_path, labels, blank_index=0, space_index=28): 105 | if ctc._kenlm_enabled() != 1: 106 | raise ImportError("pytorch-ctc not compiled with KenLM support.") 107 | result = ctc._generate_lm_trie(labels, len(labels), blank_index, space_index, kenlm_path.encode(), dictionary_path.encode(), output_path.encode()) 108 | 109 | if result != 0: 110 | raise ValueError("Error encountered generating trie") 111 | -------------------------------------------------------------------------------- /pytorch_ctc/src/cpu_binding.h: -------------------------------------------------------------------------------- 1 | typedef enum { 2 | CTC, 3 | CTC_KENLM 4 | } DecodeType ; 5 | 6 | 7 | /* scorers */ 8 | int kenlm_enabled(); 9 | void* get_kenlm_scorer(const wchar_t* label_str, int labels_size, int space_index, int blank_index, 10 | const char* lm_path, const char* trie_path); 11 | void set_kenlm_scorer_lm_weight(void *scorer, float weight); 12 | void set_kenlm_scorer_wc_weight(void *scorer, float weight); 13 | void set_kenlm_scorer_vwc_weight(void *scorer, float weight); 14 | void* get_base_scorer(); 15 | 16 | 17 | /* decoders */ 18 | void* get_ctc_beam_decoder(int num_classes, int top_paths, int beam_width, int blank_index, 19 | int merge_repeated, void *scorer, DecodeType type); 20 | 21 | 22 | /* run decoding */ 23 | int ctc_beam_decode(void *decoder, DecodeType type, 24 | THFloatTensor *probs, THIntTensor *seq_len, THIntTensor *output, 25 | THFloatTensor *scores, THIntTensor *th_out_len); 26 | 27 | 28 | /* utilities */ 29 | int generate_lm_trie(const wchar_t* labels, int size, int blank_index, int space_index, 30 | const char* lm_path, const char* dictionary_path, const char* output_path); 31 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_beam_entry.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #ifndef PYTORCH_CONTRIB_CTC_CTC_BEAM_ENTRY_H_ 14 | #define PYTORCH_CONTRIB_CTC_CTC_BEAM_ENTRY_H_ 15 | 16 | #include 17 | #include 18 | 19 | #include "Eigen/Core" 20 | //#include "tensorflow/core/platform/logging.h" 21 | //#include "tensorflow/core/platform/macros.h" 22 | //#include "tensorflow/core/platform/types.h" 23 | #include "ctc_loss_util.h" 24 | #include "util/macros.h" 25 | 26 | // The ctc_beam_search namespace holds several classes meant to be accessed only 27 | // in case of extending the CTCBeamSearch decoder to allow custom scoring 28 | // functions. 29 | // 30 | // BeamEntry is exposed through template arguments BeamScorer and BeamComparer 31 | // of CTCBeamSearch (ctc_beam_search.h). 32 | namespace pytorch { 33 | namespace ctc { 34 | namespace ctc_beam_search { 35 | 36 | struct EmptyBeamState {}; 37 | 38 | struct BeamProbability { 39 | BeamProbability() : total(kLogZero), blank(kLogZero), label(kLogZero) {} 40 | void Reset() { 41 | total = kLogZero; 42 | blank = kLogZero; 43 | label = kLogZero; 44 | } 45 | float total; 46 | float blank; 47 | float label; 48 | }; 49 | 50 | template 51 | struct BeamEntry { 52 | // Default constructor does not create a vector of children. 53 | BeamEntry() : parent(nullptr), label(-1) {} 54 | // Constructor giving parent, label, and number of children does 55 | // create a vector of children. The object pointed to by p 56 | // cannot be copied and should not be moved, otherwise parent will 57 | // become invalid. 58 | BeamEntry(BeamEntry* p, int l, int L, int blank) : parent(p), label(l) { 59 | PopulateChildren(L, blank); 60 | } 61 | inline bool Active() const { return newp.total != kLogZero; } 62 | inline bool HasChildren() const { return !children.empty(); } 63 | void PopulateChildren(int L, int blank) { 64 | if (HasChildren()) { 65 | return; 66 | } 67 | children = std::vector(L-1); 68 | for (int ci=0,cl=0; ci < L; ++ci) { 69 | if (ci == blank) { 70 | continue; 71 | } 72 | // The current object cannot be copied, and should not be moved. 73 | // Otherwise the child's parent will become invalid. 74 | auto& c = children[cl]; 75 | c.parent = this; 76 | c.label = ci; 77 | ++cl; 78 | } 79 | } 80 | inline std::vector* Children() { 81 | if (!HasChildren()) { 82 | return {}; 83 | } 84 | return &children; 85 | } 86 | inline const std::vector* Children() const { 87 | if (!HasChildren()) { 88 | return {}; 89 | } 90 | return &children; 91 | } 92 | std::vector LabelSeq(bool merge_repeated) const { 93 | std::vector labels; 94 | int prev_label = -1; 95 | const BeamEntry* c = this; 96 | while (c->parent != nullptr) { // Checking c->parent to skip root leaf. 97 | if (!merge_repeated || c->label != prev_label) { 98 | labels.push_back(c->label); 99 | } 100 | prev_label = c->label; 101 | c = c->parent; 102 | } 103 | std::reverse(labels.begin(), labels.end()); 104 | return labels; 105 | } 106 | 107 | BeamEntry* parent; 108 | int label; 109 | std::vector > children; 110 | BeamProbability oldp; 111 | BeamProbability newp; 112 | CTCBeamState state; 113 | 114 | private: 115 | TF_DISALLOW_COPY_AND_ASSIGN(BeamEntry); 116 | }; 117 | 118 | // BeamComparer is the default beam comparer provided in CTCBeamSearch. 119 | template 120 | class BeamComparer { 121 | public: 122 | virtual ~BeamComparer() {} 123 | virtual bool inline operator()(const BeamEntry* a, 124 | const BeamEntry* b) const { 125 | return a->newp.total > b->newp.total; 126 | } 127 | }; 128 | 129 | } // namespace ctc_beam_search 130 | } 131 | } 132 | 133 | #endif // PYTORCH_CONTRIB_CTC_CTC_BEAM_ENTRY_H_ 134 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_beam_scorer.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | // Collection of scoring classes that can be extended and provided to the 14 | // CTCBeamSearchDecoder to incorporate additional scoring logic (such as a 15 | // language model). 16 | // 17 | // To build a custom scorer extend and implement the pure virtual methods from 18 | // BeamScorerInterface. The default CTC decoding behavior is implemented 19 | // through BaseBeamScorer. 20 | 21 | #ifndef PYTORCH_CONTRIB_CTC_CTC_BEAM_SCORER_H_ 22 | #define PYTORCH_CONTRIB_CTC_CTC_BEAM_SCORER_H_ 23 | 24 | #include "ctc_beam_entry.h" 25 | 26 | namespace pytorch { 27 | namespace ctc { 28 | 29 | // Base implementation of a beam scorer used by default by the decoder that can 30 | // be subclassed and provided as an argument to CTCBeamSearchDecoder, if complex 31 | // scoring is required. Its main purpose is to provide a thin layer for 32 | // integrating language model scoring easily. 33 | template 34 | class BaseBeamScorer { 35 | public: 36 | virtual ~BaseBeamScorer() {} 37 | // State initialization. 38 | virtual void InitializeState(CTCBeamState* root) const {} 39 | // ExpandState is called when expanding a beam to one of its children. 40 | // Called at most once per child beam. In the simplest case, no state 41 | // expansion is done. 42 | virtual void ExpandState(const CTCBeamState& from_state, int from_label, 43 | CTCBeamState* to_state, int to_label) const {} 44 | // ExpandStateEnd is called after decoding has finished. Its purpose is to 45 | // allow a final scoring of the beam in its current state, before resorting 46 | // and retrieving the TopN requested candidates. Called at most once per beam. 47 | virtual void ExpandStateEnd(CTCBeamState* state) const {} 48 | // GetStateExpansionScore should be an inexpensive method to retrieve the 49 | // (cached) expansion score computed within ExpandState. The score is 50 | // multiplied (log-addition) with the input score at the current step from 51 | // the network. 52 | // 53 | // The score returned should be a log-probability. In the simplest case, as 54 | // there's no state expansion logic, the expansion score is zero. 55 | virtual float GetStateExpansionScore(const CTCBeamState& state, 56 | float previous_score) const { 57 | return previous_score; 58 | } 59 | // GetStateEndExpansionScore should be an inexpensive method to retrieve the 60 | // (cached) expansion score computed within ExpandStateEnd. The score is 61 | // multiplied (log-addition) with the final probability of the beam. 62 | // 63 | // The score returned should be a log-probability. 64 | virtual float GetStateEndExpansionScore(const CTCBeamState& state) const { 65 | return 0; 66 | } 67 | }; 68 | 69 | } // namespace ctc 70 | } // namespace pytorch 71 | 72 | #endif // PYTORCH_CONTRIB_CTC_CTC_BEAM_SCORER_H_ 73 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_decoder.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #ifndef PYTORCH_CONTRIB_CTC_CTC_DECODER_H_ 14 | #define PYTORCH_CONTRIB_CTC_CTC_DECODER_H_ 15 | 16 | #include "Eigen/Core" 17 | #include "util/status.h" 18 | //#include "tensorflow/core/lib/core/errors.h" 19 | //#include "tensorflow/core/lib/core/status.h" 20 | 21 | namespace pytorch { 22 | namespace ctc { 23 | 24 | // The CTCDecoder is an abstract interface to be implemented when providing a 25 | // decoding method on the timestep output of a RNN trained with CTC loss. 26 | // 27 | // The two types of decoding available are: 28 | // - greedy path, through the CTCGreedyDecoder 29 | // - beam search, through the CTCBeamSearchDecoder 30 | class CTCDecoder { 31 | public: 32 | typedef Eigen::Map SequenceLength; 33 | typedef Eigen::Map > Input; 34 | typedef std::vector> Output; 35 | typedef Eigen::Map ScoreOutput; 36 | 37 | CTCDecoder(int num_classes, int blank_index, bool merge_repeated) 38 | : num_classes_(num_classes), 39 | blank_index_(blank_index), 40 | merge_repeated_(merge_repeated) {} 41 | 42 | virtual ~CTCDecoder() {} 43 | 44 | // Dimensionality of the input/output is expected to be: 45 | // - seq_len[b] - b = 0 to batch_size_ 46 | // - input[t].rows(b) - t = 0 to timesteps; b = 0 t batch_size_ 47 | // - output.size() specifies the number of beams to be returned. 48 | // - scores(b, i) - b = 0 to batch_size; i = 0 to output.size() 49 | virtual Status Decode(const SequenceLength& seq_len, 50 | std::vector& input, 51 | std::vector* output, ScoreOutput* scores) = 0; 52 | 53 | int num_classes() { return num_classes_; } 54 | 55 | protected: 56 | int num_classes_; 57 | int blank_index_; 58 | bool merge_repeated_; 59 | }; 60 | 61 | // CTCGreedyDecoder is an implementation of the simple best path decoding 62 | // algorithm, selecting at each timestep the most likely class at each timestep. 63 | class CTCGreedyDecoder : public CTCDecoder { 64 | public: 65 | CTCGreedyDecoder(int num_classes, int blank_index, bool merge_repeated) 66 | : CTCDecoder(num_classes, blank_index, merge_repeated) {} 67 | 68 | Status Decode(const CTCDecoder::SequenceLength& seq_len, 69 | std::vector& input, 70 | std::vector* output, 71 | CTCDecoder::ScoreOutput* scores) override { 72 | int batch_size_ = input[0].cols(); 73 | if (output->empty() || (*output)[0].size() < batch_size_) { 74 | return errors::InvalidArgument( 75 | "output needs to be of size at least (1, batch_size)."); 76 | } 77 | if (scores->rows() < batch_size_ || scores->cols() == 0) { 78 | return errors::InvalidArgument( 79 | "scores needs to be of size at least (batch_size, 1)."); 80 | } 81 | // For each batch entry, identify the transitions 82 | for (int b = 0; b < batch_size_; ++b) { 83 | int seq_len_b = seq_len[b]; 84 | // Only writing to beam 0 85 | std::vector& output_b = (*output)[0][b]; 86 | 87 | int prev_class_ix = -1; 88 | (*scores)(b, 0) = 0; 89 | for (int t = 0; t < seq_len_b; ++t) { 90 | auto row = input[t].row(b); 91 | int max_class_ix; 92 | (*scores)(b, 0) += -row.maxCoeff(&max_class_ix); 93 | if (max_class_ix != blank_index_ && 94 | !(merge_repeated_ && max_class_ix == prev_class_ix)) { 95 | output_b.push_back(max_class_ix); 96 | } 97 | prev_class_ix = max_class_ix; 98 | } 99 | } 100 | return Status::OK(); 101 | } 102 | }; 103 | 104 | } // namespace ctc 105 | } // namespace pytorch 106 | 107 | #endif // PYTORCH_CONTRIB_CTC_CTC_DECODER_H_ 108 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_labels.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #ifndef CTC_LABELS_H 14 | #define CTC_LABELS_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "utf8.h" 24 | 25 | namespace pytorch { 26 | namespace ctc { 27 | 28 | class Labels { 29 | public: 30 | ~Labels() { 31 | delete char_list; 32 | } 33 | 34 | Labels(const wchar_t *char_list, int size, int blank_index, int space_index) : size(size) { 35 | this->char_list = new wchar_t[size]; 36 | for (int i = 0; i < size; i++) { 37 | this->char_list[i] = char_list[i]; 38 | char_to_label[char_list[i]] = i; 39 | } 40 | this->blank_index = blank_index; 41 | this->space_index = space_index; 42 | } 43 | 44 | bool inline IsBlank(int label) const { 45 | // If label is not contained in this Label 46 | // it must be a blank label 47 | return label == blank_index; 48 | } 49 | 50 | bool inline IsSpace(int label) const { 51 | return label == space_index; 52 | } 53 | 54 | wchar_t GetCharacter(int label) const { 55 | assert(label < size); 56 | return char_list[label]; 57 | } 58 | 59 | int GetLabel(wchar_t c) { 60 | return char_to_label[c]; 61 | } 62 | 63 | int GetSize() const { 64 | return size; 65 | } 66 | 67 | private: 68 | int size; 69 | wchar_t *char_list; 70 | int blank_index; 71 | int space_index; 72 | std::unordered_map char_to_label; 73 | 74 | void ReadFromFile(std::istream& is) { 75 | std::string all_symbols_utf8; 76 | std::getline(is, all_symbols_utf8); 77 | std::wstring all_symbols; 78 | utf8::utf8to16(all_symbols_utf8.begin(), 79 | all_symbols_utf8.end(), 80 | std::back_inserter(all_symbols)); 81 | size = all_symbols.size(); 82 | char_list = new wchar_t[size]; 83 | for (int i = 0; i < size; i++) { 84 | char_list[i] = all_symbols[i]; 85 | char_to_label[char_list[i]] = i; 86 | } 87 | } 88 | 89 | }; 90 | 91 | } // namespace ctc 92 | } // namespace tensorflow 93 | 94 | #endif //CTC_Label_H 95 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_loss_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #ifndef PYTORCH_CONTRIB_CTC_CTC_LOSS_UTIL_H_ 14 | #define PYTORCH_CONTRIB_CTC_CTC_LOSS_UTIL_H_ 15 | 16 | #include 17 | #include 18 | 19 | namespace pytorch { 20 | namespace ctc { 21 | 22 | const float kLogZero = -std::numeric_limits::infinity(); 23 | 24 | // Add logarithmic probabilities using: 25 | // ln(a + b) = ln(a) + ln(1 + exp(ln(b) - ln(a))) 26 | // The two inputs are assumed to be log probabilities. 27 | // (GravesTh) Eq. 7.18 28 | inline float LogSumExp(float log_prob_1, float log_prob_2) { 29 | // Always have 'b' be the smaller number to avoid the exponential from 30 | // blowing up. 31 | if (log_prob_1 == kLogZero && log_prob_2 == kLogZero) { 32 | return kLogZero; 33 | } else { 34 | return (log_prob_1 > log_prob_2) 35 | ? log_prob_1 + log1pf(expf(log_prob_2 - log_prob_1)) 36 | : log_prob_2 + log1pf(expf(log_prob_1 - log_prob_2)); 37 | } 38 | } 39 | 40 | } // namespace ctc 41 | } // namespace tensorflow 42 | 43 | #endif // PYTORCH_CONTRIB_CTC_CTC_LOSS_UTIL_H_ 44 | -------------------------------------------------------------------------------- /pytorch_ctc/src/ctc_trie_node.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #ifndef CTC_TRIENODE_H 14 | #define CTC_TRIENODE_H 15 | 16 | #include "lm/model.hh" 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace pytorch { 24 | namespace ctc { 25 | 26 | class TrieNode { 27 | public: 28 | TrieNode(int vocab_size) : vocab_size(vocab_size), 29 | prefixCount(0), 30 | min_score_word(0), 31 | min_unigram_score(std::numeric_limits::max()) { 32 | children = new TrieNode*[vocab_size](); 33 | } 34 | 35 | ~TrieNode() { 36 | for (int i = 0; i < vocab_size; i++) { 37 | delete children[i]; 38 | } 39 | delete children; 40 | } 41 | 42 | void WriteToStream(std::ostream& os) { 43 | WriteNode(os); 44 | for (int i = 0; i < vocab_size; i++) { 45 | if (children[i] == nullptr) { 46 | os << -1 << std::endl; 47 | } else { 48 | // Recursive call 49 | children[i]->WriteToStream(os); 50 | } 51 | } 52 | } 53 | 54 | static void ReadFromStream(std::istream& is, TrieNode* &obj, int vocab_size) { 55 | int prefixCount; 56 | is >> prefixCount; 57 | 58 | if (prefixCount == -1) { 59 | // This is an undefined child 60 | obj = nullptr; 61 | return; 62 | } 63 | 64 | obj = new TrieNode(vocab_size); 65 | obj->ReadNode(is, prefixCount); 66 | for (int i = 0; i < vocab_size; i++) { 67 | // Recursive call 68 | ReadFromStream(is, obj->children[i], vocab_size); 69 | } 70 | } 71 | 72 | void Insert(const wchar_t* word, std::function translator, 73 | lm::WordIndex lm_word, float unigram_score) { 74 | wchar_t wordCharacter = *word; 75 | prefixCount++; 76 | if (unigram_score < min_unigram_score) { 77 | min_unigram_score = unigram_score; 78 | min_score_word = lm_word; 79 | } 80 | if (wordCharacter != '\0') { 81 | int vocabIndex = translator(wordCharacter); 82 | TrieNode *child = children[vocabIndex]; 83 | if (child == nullptr) 84 | child = children[vocabIndex] = new TrieNode(vocab_size); 85 | child->Insert(word + 1, translator, lm_word, unigram_score); 86 | } 87 | } 88 | 89 | int GetFrequency() { 90 | return prefixCount; 91 | } 92 | 93 | lm::WordIndex GetMinScoreWordIndex() { 94 | return min_score_word; 95 | } 96 | 97 | float GetMinUnigramScore() { 98 | return min_unigram_score; 99 | } 100 | 101 | TrieNode *GetChildAt(int vocabIndex) { 102 | return children[vocabIndex]; 103 | } 104 | 105 | private: 106 | int vocab_size; 107 | int prefixCount; 108 | lm::WordIndex min_score_word; 109 | float min_unigram_score; 110 | TrieNode **children; 111 | 112 | void WriteNode(std::ostream& os) const { 113 | os << prefixCount << std::endl; 114 | os << min_score_word << std::endl; 115 | os << min_unigram_score << std::endl; 116 | } 117 | 118 | void ReadNode(std::istream& is, int first_input) { 119 | prefixCount = first_input; 120 | is >> min_score_word; 121 | is >> min_unigram_score; 122 | } 123 | 124 | }; 125 | 126 | } // namespace ctc 127 | } // namespace pytorch 128 | 129 | #endif //CTC_TRIENODE_H 130 | -------------------------------------------------------------------------------- /pytorch_ctc/src/util/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef PYTORCH_CONTRIB_CTC_CTC_MACROS_H_ 2 | #define PYTORCH_CONTRIB_CTC_CTC_MACROS_H_ 3 | 4 | // A macro to disallow the copy constructor and operator= functions 5 | // This is usually placed in the private: declarations for a class. 6 | #define TF_DISALLOW_COPY_AND_ASSIGN(TypeName) \ 7 | TypeName(const TypeName&) = delete; \ 8 | void operator=(const TypeName&) = delete 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pytorch_ctc/src/util/status.cpp: -------------------------------------------------------------------------------- 1 | #include "status.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | namespace pytorch { 10 | namespace ctc { 11 | Status::Status(pytorch::ctc::Code code, string msg) { 12 | assert(code != pytorch::ctc::OK); 13 | state_ = new State; 14 | state_->code = code; 15 | state_->msg = msg; 16 | } 17 | 18 | const string& Status::empty_string() { 19 | static string* empty = new string; 20 | return *empty; 21 | } 22 | 23 | string Status::ToString() const { 24 | if (state_ == nullptr) { 25 | return "OK"; 26 | } else { 27 | char tmp[30]; 28 | const char* type; 29 | switch (code()) { 30 | case pytorch::ctc::Code::CANCELLED: 31 | type = "Cancelled"; 32 | break; 33 | case pytorch::ctc::Code::INVALID_ARGUMENT: 34 | type = "Invalid argument"; 35 | break; 36 | case pytorch::ctc::Code::FAILED_PRECONDITION: 37 | type = "Failed precondition"; 38 | break; 39 | case pytorch::ctc::Code::OUT_OF_RANGE: 40 | type = "Out of range"; 41 | break; 42 | default: 43 | snprintf(tmp, sizeof(tmp), "Unknown code(%d)", 44 | static_cast(code())); 45 | type = tmp; 46 | break; 47 | } 48 | string result(type); 49 | result += ": " + state_->msg; 50 | return result; 51 | } 52 | } 53 | 54 | std::ostream& operator<<(std::ostream& os, const Status& x) { 55 | os << x.ToString(); 56 | return os; 57 | } 58 | 59 | namespace errors { 60 | Status InvalidArgument(string msg) { return Status(Code::INVALID_ARGUMENT, msg); } 61 | Status FailedPrecondition(string msg) { return Status(Code::FAILED_PRECONDITION, msg); } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /pytorch_ctc/src/util/status.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef PYTORCH_CONTRIB_CTC_CTC_STATUS_H_ 4 | #define PYTORCH_CONTRIB_CTC_CTC_STATUS_H_ 5 | 6 | using namespace std; 7 | 8 | namespace pytorch { 9 | namespace ctc { 10 | enum Code { 11 | OK, 12 | CANCELLED, 13 | INVALID_ARGUMENT, 14 | FAILED_PRECONDITION, 15 | OUT_OF_RANGE 16 | }; 17 | 18 | class Status { 19 | public: 20 | Status() : state_(NULL) {} 21 | ~Status() { delete state_; } 22 | 23 | Status(pytorch::ctc::Code code, string msg); 24 | 25 | /// Copy the specified status. 26 | Status(const Status& s); 27 | void operator=(const Status& s); 28 | 29 | static Status OK() { return Status(); } 30 | 31 | bool ok() const { return (state_ == NULL); } 32 | 33 | pytorch::ctc::Code code() const { 34 | return ok() ? pytorch::ctc::OK : state_->code; 35 | } 36 | 37 | const string& error_message() const { 38 | return ok() ? empty_string() : state_->msg; 39 | } 40 | 41 | bool operator==(const Status& x) const; 42 | bool operator!=(const Status& x) const; 43 | string ToString() const; 44 | 45 | private: 46 | static const string& empty_string(); 47 | struct State { 48 | pytorch::ctc::Code code; 49 | string msg; 50 | }; 51 | // OK status has a `NULL` state_. Otherwise, `state_` points to 52 | // a `State` structure containing the error code and message(s) 53 | State* state_; 54 | }; 55 | 56 | inline Status::Status(const Status& s) 57 | : state_((s.state_ == NULL) ? NULL : new State(*s.state_)) {} 58 | 59 | inline bool Status::operator==(const Status& x) const { 60 | return (this->state_ == x.state_) || (ToString() == x.ToString()); 61 | } 62 | 63 | inline bool Status::operator!=(const Status& x) const { return !(*this == x); } 64 | 65 | /// @ingroup core 66 | std::ostream& operator<<(std::ostream& os, const Status& x); 67 | 68 | namespace errors { 69 | Status InvalidArgument(string msg); 70 | Status FailedPrecondition(string msg); 71 | } 72 | } 73 | } 74 | 75 | #endif // PYTORCH_CONTRIB_CTC_CTC_STATUS_H_ 76 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | cffi>=1.0.0 2 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import platform 6 | import glob 7 | 8 | from distutils.core import setup, Extension 9 | from torch.utils.ffi import create_extension 10 | 11 | #Does gcc compile with this header and library? 12 | def compile_test(header, library): 13 | dummy_path = os.path.join(os.path.dirname(__file__), "dummy") 14 | command = "bash -c \"g++ -include " + header + " -l" + library + " -x c++ - <<<'int main() {}' -o " + dummy_path + " >/dev/null 2>/dev/null && rm " + dummy_path + " 2>/dev/null\"" 15 | return os.system(command) == 0 16 | 17 | # this is a hack, but makes this significantly easier 18 | include_kenlm = True 19 | ex_klm = "--exclude-kenlm" 20 | if ex_klm in sys.argv: 21 | include_kenlm=False 22 | sys.argv.remove(ex_klm) 23 | 24 | third_party_libs = ["eigen3", "utf8"] 25 | lib_sources = [] 26 | compile_args = ['-std=c++11', '-fPIC', '-w', '-O3', '-DNDEBUG'] 27 | ext_libs = ['stdc++'] 28 | 29 | if compile_test('zlib.h', 'z'): 30 | compile_args.append('-DHAVE_ZLIB') 31 | ext_libs.append('z') 32 | 33 | if compile_test('bzlib.h', 'bz2'): 34 | compile_args.append('-DHAVE_BZLIB') 35 | ext_libs.append('bz2') 36 | 37 | if compile_test('lzma.h', 'lzma'): 38 | compile_args.append('-DHAVE_XZLIB') 39 | ext_libs.append('lzma') 40 | 41 | if include_kenlm: 42 | third_party_libs.append("kenlm") 43 | compile_args.extend(['-DINCLUDE_KENLM', '-DKENLM_MAX_ORDER=6']) 44 | lib_sources = glob.glob('third_party/kenlm/util/*.cc') + glob.glob('third_party/kenlm/lm/*.cc') + glob.glob('third_party/kenlm/util/double-conversion/*.cc') 45 | lib_sources = [fn for fn in lib_sources if not (fn.endswith('main.cc') or fn.endswith('test.cc'))] 46 | 47 | third_party_includes=["third_party/" + lib for lib in third_party_libs] 48 | ctc_sources = ['pytorch_ctc/src/cpu_binding.cpp', 'pytorch_ctc/src/util/status.cpp'] 49 | ctc_headers = ['pytorch_ctc/src/cpu_binding.h',] 50 | 51 | ffi = create_extension( 52 | name='ctc_decode', 53 | package=True, 54 | language='c++', 55 | headers=ctc_headers, 56 | sources=ctc_sources + lib_sources, 57 | include_dirs=third_party_includes, 58 | with_cuda=False, 59 | libraries=ext_libs, 60 | extra_compile_args=compile_args#, '-DINCLUDE_KENLM'] 61 | ) 62 | ffi = ffi.distutils_extension() 63 | ffi.name = 'pytorch_ctc._ctc_decode' 64 | 65 | setup( 66 | name="pytorch_ctc", 67 | version="0.1", 68 | description="CTC Decoder for PyTorch based on TensorFlow's implementation", 69 | url="https://github.com/ryanleary/pytorch-ctc-decode", 70 | author="Ryan Leary", 71 | author_email="ryanleary@gmail.com", 72 | # Require cffi. 73 | install_requires=["cffi>=1.0.0"], 74 | setup_requires=["cffi>=1.0.0"], 75 | # Exclude the build files. 76 | packages=["pytorch_ctc"], 77 | # Extensions to compile. 78 | ext_modules=[ffi] 79 | ) 80 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/BooleanRedux.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_ALLANDANY_H 11 | #define EIGEN_ALLANDANY_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | struct all_unroller 19 | { 20 | typedef typename Derived::ExpressionTraits Traits; 21 | enum { 22 | col = (UnrollCount-1) / Traits::RowsAtCompileTime, 23 | row = (UnrollCount-1) % Traits::RowsAtCompileTime 24 | }; 25 | 26 | static inline bool run(const Derived &mat) 27 | { 28 | return all_unroller::run(mat) && mat.coeff(row, col); 29 | } 30 | }; 31 | 32 | template 33 | struct all_unroller 34 | { 35 | static inline bool run(const Derived &/*mat*/) { return true; } 36 | }; 37 | 38 | template 39 | struct all_unroller 40 | { 41 | static inline bool run(const Derived &) { return false; } 42 | }; 43 | 44 | template 45 | struct any_unroller 46 | { 47 | typedef typename Derived::ExpressionTraits Traits; 48 | enum { 49 | col = (UnrollCount-1) / Traits::RowsAtCompileTime, 50 | row = (UnrollCount-1) % Traits::RowsAtCompileTime 51 | }; 52 | 53 | static inline bool run(const Derived &mat) 54 | { 55 | return any_unroller::run(mat) || mat.coeff(row, col); 56 | } 57 | }; 58 | 59 | template 60 | struct any_unroller 61 | { 62 | static inline bool run(const Derived & /*mat*/) { return false; } 63 | }; 64 | 65 | template 66 | struct any_unroller 67 | { 68 | static inline bool run(const Derived &) { return false; } 69 | }; 70 | 71 | } // end namespace internal 72 | 73 | /** \returns true if all coefficients are true 74 | * 75 | * Example: \include MatrixBase_all.cpp 76 | * Output: \verbinclude MatrixBase_all.out 77 | * 78 | * \sa any(), Cwise::operator<() 79 | */ 80 | template 81 | inline bool DenseBase::all() const 82 | { 83 | typedef internal::evaluator Evaluator; 84 | enum { 85 | unroll = SizeAtCompileTime != Dynamic 86 | && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT 87 | }; 88 | Evaluator evaluator(derived()); 89 | if(unroll) 90 | return internal::all_unroller::run(evaluator); 91 | else 92 | { 93 | for(Index j = 0; j < cols(); ++j) 94 | for(Index i = 0; i < rows(); ++i) 95 | if (!evaluator.coeff(i, j)) return false; 96 | return true; 97 | } 98 | } 99 | 100 | /** \returns true if at least one coefficient is true 101 | * 102 | * \sa all() 103 | */ 104 | template 105 | inline bool DenseBase::any() const 106 | { 107 | typedef internal::evaluator Evaluator; 108 | enum { 109 | unroll = SizeAtCompileTime != Dynamic 110 | && SizeAtCompileTime * (Evaluator::CoeffReadCost + NumTraits::AddCost) <= EIGEN_UNROLLING_LIMIT 111 | }; 112 | Evaluator evaluator(derived()); 113 | if(unroll) 114 | return internal::any_unroller::run(evaluator); 115 | else 116 | { 117 | for(Index j = 0; j < cols(); ++j) 118 | for(Index i = 0; i < rows(); ++i) 119 | if (evaluator.coeff(i, j)) return true; 120 | return false; 121 | } 122 | } 123 | 124 | /** \returns the number of coefficients which evaluate to true 125 | * 126 | * \sa all(), any() 127 | */ 128 | template 129 | inline Eigen::Index DenseBase::count() const 130 | { 131 | return derived().template cast().template cast().sum(); 132 | } 133 | 134 | /** \returns true is \c *this contains at least one Not A Number (NaN). 135 | * 136 | * \sa allFinite() 137 | */ 138 | template 139 | inline bool DenseBase::hasNaN() const 140 | { 141 | #if EIGEN_COMP_MSVC || (defined __FAST_MATH__) 142 | return derived().array().isNaN().any(); 143 | #else 144 | return !((derived().array()==derived().array()).all()); 145 | #endif 146 | } 147 | 148 | /** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values. 149 | * 150 | * \sa hasNaN() 151 | */ 152 | template 153 | inline bool DenseBase::allFinite() const 154 | { 155 | #if EIGEN_COMP_MSVC || (defined __FAST_MATH__) 156 | return derived().array().isFinite().all(); 157 | #else 158 | return !((derived()-derived()).hasNaN()); 159 | #endif 160 | } 161 | 162 | } // end namespace Eigen 163 | 164 | #endif // EIGEN_ALLANDANY_H 165 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/CommaInitializer.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_COMMAINITIALIZER_H 12 | #define EIGEN_COMMAINITIALIZER_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class CommaInitializer 17 | * \ingroup Core_Module 18 | * 19 | * \brief Helper class used by the comma initializer operator 20 | * 21 | * This class is internally used to implement the comma initializer feature. It is 22 | * the return type of MatrixBase::operator<<, and most of the time this is the only 23 | * way it is used. 24 | * 25 | * \sa \blank \ref MatrixBaseCommaInitRef "MatrixBase::operator<<", CommaInitializer::finished() 26 | */ 27 | template 28 | struct CommaInitializer 29 | { 30 | typedef typename XprType::Scalar Scalar; 31 | 32 | EIGEN_DEVICE_FUNC 33 | inline CommaInitializer(XprType& xpr, const Scalar& s) 34 | : m_xpr(xpr), m_row(0), m_col(1), m_currentBlockRows(1) 35 | { 36 | m_xpr.coeffRef(0,0) = s; 37 | } 38 | 39 | template 40 | EIGEN_DEVICE_FUNC 41 | inline CommaInitializer(XprType& xpr, const DenseBase& other) 42 | : m_xpr(xpr), m_row(0), m_col(other.cols()), m_currentBlockRows(other.rows()) 43 | { 44 | m_xpr.block(0, 0, other.rows(), other.cols()) = other; 45 | } 46 | 47 | /* Copy/Move constructor which transfers ownership. This is crucial in 48 | * absence of return value optimization to avoid assertions during destruction. */ 49 | // FIXME in C++11 mode this could be replaced by a proper RValue constructor 50 | EIGEN_DEVICE_FUNC 51 | inline CommaInitializer(const CommaInitializer& o) 52 | : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) { 53 | // Mark original object as finished. In absence of R-value references we need to const_cast: 54 | const_cast(o).m_row = m_xpr.rows(); 55 | const_cast(o).m_col = m_xpr.cols(); 56 | const_cast(o).m_currentBlockRows = 0; 57 | } 58 | 59 | /* inserts a scalar value in the target matrix */ 60 | EIGEN_DEVICE_FUNC 61 | CommaInitializer& operator,(const Scalar& s) 62 | { 63 | if (m_col==m_xpr.cols()) 64 | { 65 | m_row+=m_currentBlockRows; 66 | m_col = 0; 67 | m_currentBlockRows = 1; 68 | eigen_assert(m_row 80 | EIGEN_DEVICE_FUNC 81 | CommaInitializer& operator,(const DenseBase& other) 82 | { 83 | if (m_col==m_xpr.cols() && (other.cols()!=0 || other.rows()!=m_currentBlockRows)) 84 | { 85 | m_row+=m_currentBlockRows; 86 | m_col = 0; 87 | m_currentBlockRows = other.rows(); 88 | eigen_assert(m_row+m_currentBlockRows<=m_xpr.rows() 89 | && "Too many rows passed to comma initializer (operator<<)"); 90 | } 91 | eigen_assert((m_col + other.cols() <= m_xpr.cols()) 92 | && "Too many coefficients passed to comma initializer (operator<<)"); 93 | eigen_assert(m_currentBlockRows==other.rows()); 94 | m_xpr.template block 95 | (m_row, m_col, other.rows(), other.cols()) = other; 96 | m_col += other.cols(); 97 | return *this; 98 | } 99 | 100 | EIGEN_DEVICE_FUNC 101 | inline ~CommaInitializer() 102 | #if defined VERIFY_RAISES_ASSERT && (!defined EIGEN_NO_ASSERTION_CHECKING) && defined EIGEN_EXCEPTIONS 103 | EIGEN_EXCEPTION_SPEC(Eigen::eigen_assert_exception) 104 | #endif 105 | { 106 | finished(); 107 | } 108 | 109 | /** \returns the built matrix once all its coefficients have been set. 110 | * Calling finished is 100% optional. Its purpose is to write expressions 111 | * like this: 112 | * \code 113 | * quaternion.fromRotationMatrix((Matrix3f() << axis0, axis1, axis2).finished()); 114 | * \endcode 115 | */ 116 | EIGEN_DEVICE_FUNC 117 | inline XprType& finished() { 118 | eigen_assert(((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) 119 | && m_col == m_xpr.cols() 120 | && "Too few coefficients passed to comma initializer (operator<<)"); 121 | return m_xpr; 122 | } 123 | 124 | XprType& m_xpr; // target expression 125 | Index m_row; // current row id 126 | Index m_col; // current col id 127 | Index m_currentBlockRows; // current block height 128 | }; 129 | 130 | /** \anchor MatrixBaseCommaInitRef 131 | * Convenient operator to set the coefficients of a matrix. 132 | * 133 | * The coefficients must be provided in a row major order and exactly match 134 | * the size of the matrix. Otherwise an assertion is raised. 135 | * 136 | * Example: \include MatrixBase_set.cpp 137 | * Output: \verbinclude MatrixBase_set.out 138 | * 139 | * \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary order. 140 | * 141 | * \sa CommaInitializer::finished(), class CommaInitializer 142 | */ 143 | template 144 | inline CommaInitializer DenseBase::operator<< (const Scalar& s) 145 | { 146 | return CommaInitializer(*static_cast(this), s); 147 | } 148 | 149 | /** \sa operator<<(const Scalar&) */ 150 | template 151 | template 152 | inline CommaInitializer 153 | DenseBase::operator<<(const DenseBase& other) 154 | { 155 | return CommaInitializer(*static_cast(this), other); 156 | } 157 | 158 | } // end namespace Eigen 159 | 160 | #endif // EIGEN_COMMAINITIALIZER_H 161 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/CoreIterators.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_COREITERATORS_H 11 | #define EIGEN_COREITERATORS_H 12 | 13 | namespace Eigen { 14 | 15 | /* This file contains the respective InnerIterator definition of the expressions defined in Eigen/Core 16 | */ 17 | 18 | namespace internal { 19 | 20 | template 21 | class inner_iterator_selector; 22 | 23 | } 24 | 25 | /** \class InnerIterator 26 | * \brief An InnerIterator allows to loop over the element of any matrix expression. 27 | * 28 | * \warning To be used with care because an evaluator is constructed every time an InnerIterator iterator is constructed. 29 | * 30 | * TODO: add a usage example 31 | */ 32 | template 33 | class InnerIterator 34 | { 35 | protected: 36 | typedef internal::inner_iterator_selector::Kind> IteratorType; 37 | typedef internal::evaluator EvaluatorType; 38 | typedef typename internal::traits::Scalar Scalar; 39 | public: 40 | /** Construct an iterator over the \a outerId -th row or column of \a xpr */ 41 | InnerIterator(const XprType &xpr, const Index &outerId) 42 | : m_eval(xpr), m_iter(m_eval, outerId, xpr.innerSize()) 43 | {} 44 | 45 | /// \returns the value of the current coefficient. 46 | EIGEN_STRONG_INLINE Scalar value() const { return m_iter.value(); } 47 | /** Increment the iterator \c *this to the next non-zero coefficient. 48 | * Explicit zeros are not skipped over. To skip explicit zeros, see class SparseView 49 | */ 50 | EIGEN_STRONG_INLINE InnerIterator& operator++() { m_iter.operator++(); return *this; } 51 | /// \returns the column or row index of the current coefficient. 52 | EIGEN_STRONG_INLINE Index index() const { return m_iter.index(); } 53 | /// \returns the row index of the current coefficient. 54 | EIGEN_STRONG_INLINE Index row() const { return m_iter.row(); } 55 | /// \returns the column index of the current coefficient. 56 | EIGEN_STRONG_INLINE Index col() const { return m_iter.col(); } 57 | /// \returns \c true if the iterator \c *this still references a valid coefficient. 58 | EIGEN_STRONG_INLINE operator bool() const { return m_iter; } 59 | 60 | protected: 61 | EvaluatorType m_eval; 62 | IteratorType m_iter; 63 | private: 64 | // If you get here, then you're not using the right InnerIterator type, e.g.: 65 | // SparseMatrix A; 66 | // SparseMatrix::InnerIterator it(A,0); 67 | template InnerIterator(const EigenBase&,Index outer); 68 | }; 69 | 70 | namespace internal { 71 | 72 | // Generic inner iterator implementation for dense objects 73 | template 74 | class inner_iterator_selector 75 | { 76 | protected: 77 | typedef evaluator EvaluatorType; 78 | typedef typename traits::Scalar Scalar; 79 | enum { IsRowMajor = (XprType::Flags&RowMajorBit)==RowMajorBit }; 80 | 81 | public: 82 | EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &innerSize) 83 | : m_eval(eval), m_inner(0), m_outer(outerId), m_end(innerSize) 84 | {} 85 | 86 | EIGEN_STRONG_INLINE Scalar value() const 87 | { 88 | return (IsRowMajor) ? m_eval.coeff(m_outer, m_inner) 89 | : m_eval.coeff(m_inner, m_outer); 90 | } 91 | 92 | EIGEN_STRONG_INLINE inner_iterator_selector& operator++() { m_inner++; return *this; } 93 | 94 | EIGEN_STRONG_INLINE Index index() const { return m_inner; } 95 | inline Index row() const { return IsRowMajor ? m_outer : index(); } 96 | inline Index col() const { return IsRowMajor ? index() : m_outer; } 97 | 98 | EIGEN_STRONG_INLINE operator bool() const { return m_inner < m_end && m_inner>=0; } 99 | 100 | protected: 101 | const EvaluatorType& m_eval; 102 | Index m_inner; 103 | const Index m_outer; 104 | const Index m_end; 105 | }; 106 | 107 | // For iterator-based evaluator, inner-iterator is already implemented as 108 | // evaluator<>::InnerIterator 109 | template 110 | class inner_iterator_selector 111 | : public evaluator::InnerIterator 112 | { 113 | protected: 114 | typedef typename evaluator::InnerIterator Base; 115 | typedef evaluator EvaluatorType; 116 | 117 | public: 118 | EIGEN_STRONG_INLINE inner_iterator_selector(const EvaluatorType &eval, const Index &outerId, const Index &/*innerSize*/) 119 | : Base(eval, outerId) 120 | {} 121 | }; 122 | 123 | } // end namespace internal 124 | 125 | } // end namespace Eigen 126 | 127 | #endif // EIGEN_COREITERATORS_H 128 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/CwiseUnaryOp.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 | // 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_CWISE_UNARY_OP_H 12 | #define EIGEN_CWISE_UNARY_OP_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | template 18 | struct traits > 19 | : traits 20 | { 21 | typedef typename result_of< 22 | UnaryOp(const typename XprType::Scalar&) 23 | >::type Scalar; 24 | typedef typename XprType::Nested XprTypeNested; 25 | typedef typename remove_reference::type _XprTypeNested; 26 | enum { 27 | Flags = _XprTypeNested::Flags & RowMajorBit 28 | }; 29 | }; 30 | } 31 | 32 | template 33 | class CwiseUnaryOpImpl; 34 | 35 | /** \class CwiseUnaryOp 36 | * \ingroup Core_Module 37 | * 38 | * \brief Generic expression where a coefficient-wise unary operator is applied to an expression 39 | * 40 | * \tparam UnaryOp template functor implementing the operator 41 | * \tparam XprType the type of the expression to which we are applying the unary operator 42 | * 43 | * This class represents an expression where a unary operator is applied to an expression. 44 | * It is the return type of all operations taking exactly 1 input expression, regardless of the 45 | * presence of other inputs such as scalars. For example, the operator* in the expression 3*matrix 46 | * is considered unary, because only the right-hand side is an expression, and its 47 | * return type is a specialization of CwiseUnaryOp. 48 | * 49 | * Most of the time, this is the only way that it is used, so you typically don't have to name 50 | * CwiseUnaryOp types explicitly. 51 | * 52 | * \sa MatrixBase::unaryExpr(const CustomUnaryOp &) const, class CwiseBinaryOp, class CwiseNullaryOp 53 | */ 54 | template 55 | class CwiseUnaryOp : public CwiseUnaryOpImpl::StorageKind>, internal::no_assignment_operator 56 | { 57 | public: 58 | 59 | typedef typename CwiseUnaryOpImpl::StorageKind>::Base Base; 60 | EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp) 61 | typedef typename internal::ref_selector::type XprTypeNested; 62 | typedef typename internal::remove_all::type NestedExpression; 63 | 64 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 65 | explicit CwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp()) 66 | : m_xpr(xpr), m_functor(func) {} 67 | 68 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 69 | Index rows() const { return m_xpr.rows(); } 70 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 71 | Index cols() const { return m_xpr.cols(); } 72 | 73 | /** \returns the functor representing the unary operation */ 74 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 75 | const UnaryOp& functor() const { return m_functor; } 76 | 77 | /** \returns the nested expression */ 78 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 79 | const typename internal::remove_all::type& 80 | nestedExpression() const { return m_xpr; } 81 | 82 | /** \returns the nested expression */ 83 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE 84 | typename internal::remove_all::type& 85 | nestedExpression() { return m_xpr; } 86 | 87 | protected: 88 | XprTypeNested m_xpr; 89 | const UnaryOp m_functor; 90 | }; 91 | 92 | // Generic API dispatcher 93 | template 94 | class CwiseUnaryOpImpl 95 | : public internal::generic_xpr_base >::type 96 | { 97 | public: 98 | typedef typename internal::generic_xpr_base >::type Base; 99 | }; 100 | 101 | } // end namespace Eigen 102 | 103 | #endif // EIGEN_CWISE_UNARY_OP_H 104 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/CwiseUnaryView.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_CWISE_UNARY_VIEW_H 11 | #define EIGEN_CWISE_UNARY_VIEW_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | template 17 | struct traits > 18 | : traits 19 | { 20 | typedef typename result_of< 21 | ViewOp(const typename traits::Scalar&) 22 | >::type Scalar; 23 | typedef typename MatrixType::Nested MatrixTypeNested; 24 | typedef typename remove_all::type _MatrixTypeNested; 25 | enum { 26 | FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, 27 | Flags = traits<_MatrixTypeNested>::Flags & (RowMajorBit | FlagsLvalueBit | DirectAccessBit), // FIXME DirectAccessBit should not be handled by expressions 28 | MatrixTypeInnerStride = inner_stride_at_compile_time::ret, 29 | // need to cast the sizeof's from size_t to int explicitly, otherwise: 30 | // "error: no integral type can represent all of the enumerator values 31 | InnerStrideAtCompileTime = MatrixTypeInnerStride == Dynamic 32 | ? int(Dynamic) 33 | : int(MatrixTypeInnerStride) * int(sizeof(typename traits::Scalar) / sizeof(Scalar)), 34 | OuterStrideAtCompileTime = outer_stride_at_compile_time::ret == Dynamic 35 | ? int(Dynamic) 36 | : outer_stride_at_compile_time::ret * int(sizeof(typename traits::Scalar) / sizeof(Scalar)) 37 | }; 38 | }; 39 | } 40 | 41 | template 42 | class CwiseUnaryViewImpl; 43 | 44 | /** \class CwiseUnaryView 45 | * \ingroup Core_Module 46 | * 47 | * \brief Generic lvalue expression of a coefficient-wise unary operator of a matrix or a vector 48 | * 49 | * \tparam ViewOp template functor implementing the view 50 | * \tparam MatrixType the type of the matrix we are applying the unary operator 51 | * 52 | * This class represents a lvalue expression of a generic unary view operator of a matrix or a vector. 53 | * It is the return type of real() and imag(), and most of the time this is the only way it is used. 54 | * 55 | * \sa MatrixBase::unaryViewExpr(const CustomUnaryOp &) const, class CwiseUnaryOp 56 | */ 57 | template 58 | class CwiseUnaryView : public CwiseUnaryViewImpl::StorageKind> 59 | { 60 | public: 61 | 62 | typedef typename CwiseUnaryViewImpl::StorageKind>::Base Base; 63 | EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryView) 64 | typedef typename internal::ref_selector::non_const_type MatrixTypeNested; 65 | typedef typename internal::remove_all::type NestedExpression; 66 | 67 | explicit inline CwiseUnaryView(MatrixType& mat, const ViewOp& func = ViewOp()) 68 | : m_matrix(mat), m_functor(func) {} 69 | 70 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryView) 71 | 72 | EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); } 73 | EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); } 74 | 75 | /** \returns the functor representing unary operation */ 76 | const ViewOp& functor() const { return m_functor; } 77 | 78 | /** \returns the nested expression */ 79 | const typename internal::remove_all::type& 80 | nestedExpression() const { return m_matrix; } 81 | 82 | /** \returns the nested expression */ 83 | typename internal::remove_reference::type& 84 | nestedExpression() { return m_matrix.const_cast_derived(); } 85 | 86 | protected: 87 | MatrixTypeNested m_matrix; 88 | ViewOp m_functor; 89 | }; 90 | 91 | // Generic API dispatcher 92 | template 93 | class CwiseUnaryViewImpl 94 | : public internal::generic_xpr_base >::type 95 | { 96 | public: 97 | typedef typename internal::generic_xpr_base >::type Base; 98 | }; 99 | 100 | template 101 | class CwiseUnaryViewImpl 102 | : public internal::dense_xpr_base< CwiseUnaryView >::type 103 | { 104 | public: 105 | 106 | typedef CwiseUnaryView Derived; 107 | typedef typename internal::dense_xpr_base< CwiseUnaryView >::type Base; 108 | 109 | EIGEN_DENSE_PUBLIC_INTERFACE(Derived) 110 | EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) 111 | 112 | EIGEN_DEVICE_FUNC inline Scalar* data() { return &(this->coeffRef(0)); } 113 | EIGEN_DEVICE_FUNC inline const Scalar* data() const { return &(this->coeff(0)); } 114 | 115 | EIGEN_DEVICE_FUNC inline Index innerStride() const 116 | { 117 | return derived().nestedExpression().innerStride() * sizeof(typename internal::traits::Scalar) / sizeof(Scalar); 118 | } 119 | 120 | EIGEN_DEVICE_FUNC inline Index outerStride() const 121 | { 122 | return derived().nestedExpression().outerStride() * sizeof(typename internal::traits::Scalar) / sizeof(Scalar); 123 | } 124 | }; 125 | 126 | } // end namespace Eigen 127 | 128 | #endif // EIGEN_CWISE_UNARY_VIEW_H 129 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/EigenBase.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 | // Copyright (C) 2009 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_EIGENBASE_H 12 | #define EIGEN_EIGENBASE_H 13 | 14 | namespace Eigen { 15 | 16 | /** \class EigenBase 17 | * 18 | * Common base class for all classes T such that MatrixBase has an operator=(T) and a constructor MatrixBase(T). 19 | * 20 | * In other words, an EigenBase object is an object that can be copied into a MatrixBase. 21 | * 22 | * Besides MatrixBase-derived classes, this also includes special matrix classes such as diagonal matrices, etc. 23 | * 24 | * Notice that this class is trivial, it is only used to disambiguate overloaded functions. 25 | * 26 | * \sa \blank \ref TopicClassHierarchy 27 | */ 28 | template struct EigenBase 29 | { 30 | // typedef typename internal::plain_matrix_type::type PlainObject; 31 | 32 | /** \brief The interface type of indices 33 | * \details To change this, \c \#define the preprocessor symbol \c EIGEN_DEFAULT_DENSE_INDEX_TYPE. 34 | * \deprecated Since Eigen 3.3, its usage is deprecated. Use Eigen::Index instead. 35 | * \sa StorageIndex, \ref TopicPreprocessorDirectives. 36 | */ 37 | typedef Eigen::Index Index; 38 | 39 | // FIXME is it needed? 40 | typedef typename internal::traits::StorageKind StorageKind; 41 | 42 | /** \returns a reference to the derived object */ 43 | EIGEN_DEVICE_FUNC 44 | Derived& derived() { return *static_cast(this); } 45 | /** \returns a const reference to the derived object */ 46 | EIGEN_DEVICE_FUNC 47 | const Derived& derived() const { return *static_cast(this); } 48 | 49 | EIGEN_DEVICE_FUNC 50 | inline Derived& const_cast_derived() const 51 | { return *static_cast(const_cast(this)); } 52 | EIGEN_DEVICE_FUNC 53 | inline const Derived& const_derived() const 54 | { return *static_cast(this); } 55 | 56 | /** \returns the number of rows. \sa cols(), RowsAtCompileTime */ 57 | EIGEN_DEVICE_FUNC 58 | inline Index rows() const { return derived().rows(); } 59 | /** \returns the number of columns. \sa rows(), ColsAtCompileTime*/ 60 | EIGEN_DEVICE_FUNC 61 | inline Index cols() const { return derived().cols(); } 62 | /** \returns the number of coefficients, which is rows()*cols(). 63 | * \sa rows(), cols(), SizeAtCompileTime. */ 64 | EIGEN_DEVICE_FUNC 65 | inline Index size() const { return rows() * cols(); } 66 | 67 | /** \internal Don't use it, but do the equivalent: \code dst = *this; \endcode */ 68 | template 69 | EIGEN_DEVICE_FUNC 70 | inline void evalTo(Dest& dst) const 71 | { derived().evalTo(dst); } 72 | 73 | /** \internal Don't use it, but do the equivalent: \code dst += *this; \endcode */ 74 | template 75 | EIGEN_DEVICE_FUNC 76 | inline void addTo(Dest& dst) const 77 | { 78 | // This is the default implementation, 79 | // derived class can reimplement it in a more optimized way. 80 | typename Dest::PlainObject res(rows(),cols()); 81 | evalTo(res); 82 | dst += res; 83 | } 84 | 85 | /** \internal Don't use it, but do the equivalent: \code dst -= *this; \endcode */ 86 | template 87 | EIGEN_DEVICE_FUNC 88 | inline void subTo(Dest& dst) const 89 | { 90 | // This is the default implementation, 91 | // derived class can reimplement it in a more optimized way. 92 | typename Dest::PlainObject res(rows(),cols()); 93 | evalTo(res); 94 | dst -= res; 95 | } 96 | 97 | /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheRight(*this); \endcode */ 98 | template 99 | EIGEN_DEVICE_FUNC inline void applyThisOnTheRight(Dest& dst) const 100 | { 101 | // This is the default implementation, 102 | // derived class can reimplement it in a more optimized way. 103 | dst = dst * this->derived(); 104 | } 105 | 106 | /** \internal Don't use it, but do the equivalent: \code dst.applyOnTheLeft(*this); \endcode */ 107 | template 108 | EIGEN_DEVICE_FUNC inline void applyThisOnTheLeft(Dest& dst) const 109 | { 110 | // This is the default implementation, 111 | // derived class can reimplement it in a more optimized way. 112 | dst = this->derived() * dst; 113 | } 114 | 115 | }; 116 | 117 | /*************************************************************************** 118 | * Implementation of matrix base methods 119 | ***************************************************************************/ 120 | 121 | /** \brief Copies the generic expression \a other into *this. 122 | * 123 | * \details The expression must provide a (templated) evalTo(Derived& dst) const 124 | * function which does the actual job. In practice, this allows any user to write 125 | * its own special matrix without having to modify MatrixBase 126 | * 127 | * \returns a reference to *this. 128 | */ 129 | template 130 | template 131 | Derived& DenseBase::operator=(const EigenBase &other) 132 | { 133 | call_assignment(derived(), other.derived()); 134 | return derived(); 135 | } 136 | 137 | template 138 | template 139 | Derived& DenseBase::operator+=(const EigenBase &other) 140 | { 141 | call_assignment(derived(), other.derived(), internal::add_assign_op()); 142 | return derived(); 143 | } 144 | 145 | template 146 | template 147 | Derived& DenseBase::operator-=(const EigenBase &other) 148 | { 149 | call_assignment(derived(), other.derived(), internal::sub_assign_op()); 150 | return derived(); 151 | } 152 | 153 | } // end namespace Eigen 154 | 155 | #endif // EIGEN_EIGENBASE_H 156 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/ForceAlignedAccess.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_FORCEALIGNEDACCESS_H 11 | #define EIGEN_FORCEALIGNEDACCESS_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class ForceAlignedAccess 16 | * \ingroup Core_Module 17 | * 18 | * \brief Enforce aligned packet loads and stores regardless of what is requested 19 | * 20 | * \param ExpressionType the type of the object of which we are forcing aligned packet access 21 | * 22 | * This class is the return type of MatrixBase::forceAlignedAccess() 23 | * and most of the time this is the only way it is used. 24 | * 25 | * \sa MatrixBase::forceAlignedAccess() 26 | */ 27 | 28 | namespace internal { 29 | template 30 | struct traits > : public traits 31 | {}; 32 | } 33 | 34 | template class ForceAlignedAccess 35 | : public internal::dense_xpr_base< ForceAlignedAccess >::type 36 | { 37 | public: 38 | 39 | typedef typename internal::dense_xpr_base::type Base; 40 | EIGEN_DENSE_PUBLIC_INTERFACE(ForceAlignedAccess) 41 | 42 | EIGEN_DEVICE_FUNC explicit inline ForceAlignedAccess(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 | private: 99 | ForceAlignedAccess& operator=(const ForceAlignedAccess&); 100 | }; 101 | 102 | /** \returns an expression of *this with forced aligned access 103 | * \sa forceAlignedAccessIf(),class ForceAlignedAccess 104 | */ 105 | template 106 | inline const ForceAlignedAccess 107 | MatrixBase::forceAlignedAccess() const 108 | { 109 | return ForceAlignedAccess(derived()); 110 | } 111 | 112 | /** \returns an expression of *this with forced aligned access 113 | * \sa forceAlignedAccessIf(), class ForceAlignedAccess 114 | */ 115 | template 116 | inline ForceAlignedAccess 117 | MatrixBase::forceAlignedAccess() 118 | { 119 | return ForceAlignedAccess(derived()); 120 | } 121 | 122 | /** \returns an expression of *this with forced aligned access if \a Enable is true. 123 | * \sa forceAlignedAccess(), class ForceAlignedAccess 124 | */ 125 | template 126 | template 127 | inline typename internal::add_const_on_value_type,Derived&>::type>::type 128 | MatrixBase::forceAlignedAccessIf() const 129 | { 130 | return derived(); // FIXME This should not work but apparently is never used 131 | } 132 | 133 | /** \returns an expression of *this with forced aligned access if \a Enable is true. 134 | * \sa forceAlignedAccess(), class ForceAlignedAccess 135 | */ 136 | template 137 | template 138 | inline typename internal::conditional,Derived&>::type 139 | MatrixBase::forceAlignedAccessIf() 140 | { 141 | return derived(); // FIXME This should not work but apparently is never used 142 | } 143 | 144 | } // end namespace Eigen 145 | 146 | #endif // EIGEN_FORCEALIGNEDACCESS_H 147 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/Fuzzy.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 | // Copyright (C) 2008 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_FUZZY_H 12 | #define EIGEN_FUZZY_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal 17 | { 18 | 19 | template::IsInteger> 20 | struct isApprox_selector 21 | { 22 | EIGEN_DEVICE_FUNC 23 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) 24 | { 25 | typename internal::nested_eval::type nested(x); 26 | typename internal::nested_eval::type otherNested(y); 27 | return (nested - otherNested).cwiseAbs2().sum() <= prec * prec * numext::mini(nested.cwiseAbs2().sum(), otherNested.cwiseAbs2().sum()); 28 | } 29 | }; 30 | 31 | template 32 | struct isApprox_selector 33 | { 34 | EIGEN_DEVICE_FUNC 35 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar&) 36 | { 37 | return x.matrix() == y.matrix(); 38 | } 39 | }; 40 | 41 | template::IsInteger> 42 | struct isMuchSmallerThan_object_selector 43 | { 44 | EIGEN_DEVICE_FUNC 45 | static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) 46 | { 47 | return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum(); 48 | } 49 | }; 50 | 51 | template 52 | struct isMuchSmallerThan_object_selector 53 | { 54 | EIGEN_DEVICE_FUNC 55 | static bool run(const Derived& x, const OtherDerived&, const typename Derived::RealScalar&) 56 | { 57 | return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); 58 | } 59 | }; 60 | 61 | template::IsInteger> 62 | struct isMuchSmallerThan_scalar_selector 63 | { 64 | EIGEN_DEVICE_FUNC 65 | static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec) 66 | { 67 | return x.cwiseAbs2().sum() <= numext::abs2(prec * y); 68 | } 69 | }; 70 | 71 | template 72 | struct isMuchSmallerThan_scalar_selector 73 | { 74 | EIGEN_DEVICE_FUNC 75 | static bool run(const Derived& x, const typename Derived::RealScalar&, const typename Derived::RealScalar&) 76 | { 77 | return x.matrix() == Derived::Zero(x.rows(), x.cols()).matrix(); 78 | } 79 | }; 80 | 81 | } // end namespace internal 82 | 83 | 84 | /** \returns \c true if \c *this is approximately equal to \a other, within the precision 85 | * determined by \a prec. 86 | * 87 | * \note The fuzzy compares are done multiplicatively. Two vectors \f$ v \f$ and \f$ w \f$ 88 | * are considered to be approximately equal within precision \f$ p \f$ if 89 | * \f[ \Vert v - w \Vert \leqslant p\,\min(\Vert v\Vert, \Vert w\Vert). \f] 90 | * For matrices, the comparison is done using the Hilbert-Schmidt norm (aka Frobenius norm 91 | * L2 norm). 92 | * 93 | * \note Because of the multiplicativeness of this comparison, one can't use this function 94 | * to check whether \c *this is approximately equal to the zero matrix or vector. 95 | * Indeed, \c isApprox(zero) returns false unless \c *this itself is exactly the zero matrix 96 | * or vector. If you want to test whether \c *this is zero, use internal::isMuchSmallerThan(const 97 | * RealScalar&, RealScalar) instead. 98 | * 99 | * \sa internal::isMuchSmallerThan(const RealScalar&, RealScalar) const 100 | */ 101 | template 102 | template 103 | bool DenseBase::isApprox( 104 | const DenseBase& other, 105 | const RealScalar& prec 106 | ) const 107 | { 108 | return internal::isApprox_selector::run(derived(), other.derived(), prec); 109 | } 110 | 111 | /** \returns \c true if the norm of \c *this is much smaller than \a other, 112 | * within the precision determined by \a prec. 113 | * 114 | * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is 115 | * considered to be much smaller than \f$ x \f$ within precision \f$ p \f$ if 116 | * \f[ \Vert v \Vert \leqslant p\,\vert x\vert. \f] 117 | * 118 | * For matrices, the comparison is done using the Hilbert-Schmidt norm. For this reason, 119 | * the value of the reference scalar \a other should come from the Hilbert-Schmidt norm 120 | * of a reference matrix of same dimensions. 121 | * 122 | * \sa isApprox(), isMuchSmallerThan(const DenseBase&, RealScalar) const 123 | */ 124 | template 125 | bool DenseBase::isMuchSmallerThan( 126 | const typename NumTraits::Real& other, 127 | const RealScalar& prec 128 | ) const 129 | { 130 | return internal::isMuchSmallerThan_scalar_selector::run(derived(), other, prec); 131 | } 132 | 133 | /** \returns \c true if the norm of \c *this is much smaller than the norm of \a other, 134 | * within the precision determined by \a prec. 135 | * 136 | * \note The fuzzy compares are done multiplicatively. A vector \f$ v \f$ is 137 | * considered to be much smaller than a vector \f$ w \f$ within precision \f$ p \f$ if 138 | * \f[ \Vert v \Vert \leqslant p\,\Vert w\Vert. \f] 139 | * For matrices, the comparison is done using the Hilbert-Schmidt norm. 140 | * 141 | * \sa isApprox(), isMuchSmallerThan(const RealScalar&, RealScalar) const 142 | */ 143 | template 144 | template 145 | bool DenseBase::isMuchSmallerThan( 146 | const DenseBase& other, 147 | const RealScalar& prec 148 | ) const 149 | { 150 | return internal::isMuchSmallerThan_object_selector::run(derived(), other.derived(), prec); 151 | } 152 | 153 | } // end namespace Eigen 154 | 155 | #endif // EIGEN_FUZZY_H 156 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/Replicate.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_REPLICATE_H 11 | #define EIGEN_REPLICATE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | template 17 | struct traits > 18 | : traits 19 | { 20 | typedef typename MatrixType::Scalar Scalar; 21 | typedef typename traits::StorageKind StorageKind; 22 | typedef typename traits::XprKind XprKind; 23 | typedef typename ref_selector::type MatrixTypeNested; 24 | typedef typename remove_reference::type _MatrixTypeNested; 25 | enum { 26 | RowsAtCompileTime = RowFactor==Dynamic || int(MatrixType::RowsAtCompileTime)==Dynamic 27 | ? Dynamic 28 | : RowFactor * MatrixType::RowsAtCompileTime, 29 | ColsAtCompileTime = ColFactor==Dynamic || int(MatrixType::ColsAtCompileTime)==Dynamic 30 | ? Dynamic 31 | : ColFactor * MatrixType::ColsAtCompileTime, 32 | //FIXME we don't propagate the max sizes !!! 33 | MaxRowsAtCompileTime = RowsAtCompileTime, 34 | MaxColsAtCompileTime = ColsAtCompileTime, 35 | IsRowMajor = MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1 ? 1 36 | : MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1 ? 0 37 | : (MatrixType::Flags & RowMajorBit) ? 1 : 0, 38 | 39 | // FIXME enable DirectAccess with negative strides? 40 | Flags = IsRowMajor ? RowMajorBit : 0 41 | }; 42 | }; 43 | } 44 | 45 | /** 46 | * \class Replicate 47 | * \ingroup Core_Module 48 | * 49 | * \brief Expression of the multiple replication of a matrix or vector 50 | * 51 | * \tparam MatrixType the type of the object we are replicating 52 | * \tparam RowFactor number of repetitions at compile time along the vertical direction, can be Dynamic. 53 | * \tparam ColFactor number of repetitions at compile time along the horizontal direction, can be Dynamic. 54 | * 55 | * This class represents an expression of the multiple replication of a matrix or vector. 56 | * It is the return type of DenseBase::replicate() and most of the time 57 | * this is the only way it is used. 58 | * 59 | * \sa DenseBase::replicate() 60 | */ 61 | template class Replicate 62 | : public internal::dense_xpr_base< Replicate >::type 63 | { 64 | typedef typename internal::traits::MatrixTypeNested MatrixTypeNested; 65 | typedef typename internal::traits::_MatrixTypeNested _MatrixTypeNested; 66 | public: 67 | 68 | typedef typename internal::dense_xpr_base::type Base; 69 | EIGEN_DENSE_PUBLIC_INTERFACE(Replicate) 70 | typedef typename internal::remove_all::type NestedExpression; 71 | 72 | template 73 | EIGEN_DEVICE_FUNC 74 | inline explicit Replicate(const OriginalMatrixType& matrix) 75 | : m_matrix(matrix), m_rowFactor(RowFactor), m_colFactor(ColFactor) 76 | { 77 | EIGEN_STATIC_ASSERT((internal::is_same::type,OriginalMatrixType>::value), 78 | THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) 79 | eigen_assert(RowFactor!=Dynamic && ColFactor!=Dynamic); 80 | } 81 | 82 | template 83 | EIGEN_DEVICE_FUNC 84 | inline Replicate(const OriginalMatrixType& matrix, Index rowFactor, Index colFactor) 85 | : m_matrix(matrix), m_rowFactor(rowFactor), m_colFactor(colFactor) 86 | { 87 | EIGEN_STATIC_ASSERT((internal::is_same::type,OriginalMatrixType>::value), 88 | THE_MATRIX_OR_EXPRESSION_THAT_YOU_PASSED_DOES_NOT_HAVE_THE_EXPECTED_TYPE) 89 | } 90 | 91 | EIGEN_DEVICE_FUNC 92 | inline Index rows() const { return m_matrix.rows() * m_rowFactor.value(); } 93 | EIGEN_DEVICE_FUNC 94 | inline Index cols() const { return m_matrix.cols() * m_colFactor.value(); } 95 | 96 | EIGEN_DEVICE_FUNC 97 | const _MatrixTypeNested& nestedExpression() const 98 | { 99 | return m_matrix; 100 | } 101 | 102 | protected: 103 | MatrixTypeNested m_matrix; 104 | const internal::variable_if_dynamic m_rowFactor; 105 | const internal::variable_if_dynamic m_colFactor; 106 | }; 107 | 108 | /** 109 | * \return an expression of the replication of \c *this 110 | * 111 | * Example: \include MatrixBase_replicate.cpp 112 | * Output: \verbinclude MatrixBase_replicate.out 113 | * 114 | * \sa VectorwiseOp::replicate(), DenseBase::replicate(Index,Index), class Replicate 115 | */ 116 | template 117 | template 118 | const Replicate 119 | DenseBase::replicate() const 120 | { 121 | return Replicate(derived()); 122 | } 123 | 124 | /** 125 | * \return an expression of the replication of each column (or row) of \c *this 126 | * 127 | * Example: \include DirectionWise_replicate_int.cpp 128 | * Output: \verbinclude DirectionWise_replicate_int.out 129 | * 130 | * \sa VectorwiseOp::replicate(), DenseBase::replicate(), class Replicate 131 | */ 132 | template 133 | const typename VectorwiseOp::ReplicateReturnType 134 | VectorwiseOp::replicate(Index factor) const 135 | { 136 | return typename VectorwiseOp::ReplicateReturnType 137 | (_expression(),Direction==Vertical?factor:1,Direction==Horizontal?factor:1); 138 | } 139 | 140 | } // end namespace Eigen 141 | 142 | #endif // EIGEN_REPLICATE_H 143 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/ReturnByValue.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 | // Copyright (C) 2009-2010 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_RETURNBYVALUE_H 12 | #define EIGEN_RETURNBYVALUE_H 13 | 14 | namespace Eigen { 15 | 16 | namespace internal { 17 | 18 | template 19 | struct traits > 20 | : public traits::ReturnType> 21 | { 22 | enum { 23 | // We're disabling the DirectAccess because e.g. the constructor of 24 | // the Block-with-DirectAccess expression requires to have a coeffRef method. 25 | // Also, we don't want to have to implement the stride stuff. 26 | Flags = (traits::ReturnType>::Flags 27 | | EvalBeforeNestingBit) & ~DirectAccessBit 28 | }; 29 | }; 30 | 31 | /* The ReturnByValue object doesn't even have a coeff() method. 32 | * So the only way that nesting it in an expression can work, is by evaluating it into a plain matrix. 33 | * So internal::nested always gives the plain return matrix type. 34 | * 35 | * FIXME: I don't understand why we need this specialization: isn't this taken care of by the EvalBeforeNestingBit ?? 36 | * Answer: EvalBeforeNestingBit should be deprecated since we have the evaluators 37 | */ 38 | template 39 | struct nested_eval, n, PlainObject> 40 | { 41 | typedef typename traits::ReturnType type; 42 | }; 43 | 44 | } // end namespace internal 45 | 46 | /** \class ReturnByValue 47 | * \ingroup Core_Module 48 | * 49 | */ 50 | template class ReturnByValue 51 | : public internal::dense_xpr_base< ReturnByValue >::type, internal::no_assignment_operator 52 | { 53 | public: 54 | typedef typename internal::traits::ReturnType ReturnType; 55 | 56 | typedef typename internal::dense_xpr_base::type Base; 57 | EIGEN_DENSE_PUBLIC_INTERFACE(ReturnByValue) 58 | 59 | template 60 | EIGEN_DEVICE_FUNC 61 | inline void evalTo(Dest& dst) const 62 | { static_cast(this)->evalTo(dst); } 63 | EIGEN_DEVICE_FUNC inline Index rows() const { return static_cast(this)->rows(); } 64 | EIGEN_DEVICE_FUNC inline Index cols() const { return static_cast(this)->cols(); } 65 | 66 | #ifndef EIGEN_PARSED_BY_DOXYGEN 67 | #define Unusable YOU_ARE_TRYING_TO_ACCESS_A_SINGLE_COEFFICIENT_IN_A_SPECIAL_EXPRESSION_WHERE_THAT_IS_NOT_ALLOWED_BECAUSE_THAT_WOULD_BE_INEFFICIENT 68 | class Unusable{ 69 | Unusable(const Unusable&) {} 70 | Unusable& operator=(const Unusable&) {return *this;} 71 | }; 72 | const Unusable& coeff(Index) const { return *reinterpret_cast(this); } 73 | const Unusable& coeff(Index,Index) const { return *reinterpret_cast(this); } 74 | Unusable& coeffRef(Index) { return *reinterpret_cast(this); } 75 | Unusable& coeffRef(Index,Index) { return *reinterpret_cast(this); } 76 | #undef Unusable 77 | #endif 78 | }; 79 | 80 | template 81 | template 82 | Derived& DenseBase::operator=(const ReturnByValue& other) 83 | { 84 | other.evalTo(derived()); 85 | return derived(); 86 | } 87 | 88 | namespace internal { 89 | 90 | // Expression is evaluated in a temporary; default implementation of Assignment is bypassed so that 91 | // when a ReturnByValue expression is assigned, the evaluator is not constructed. 92 | // TODO: Finalize port to new regime; ReturnByValue should not exist in the expression world 93 | 94 | template 95 | struct evaluator > 96 | : public evaluator::ReturnType> 97 | { 98 | typedef ReturnByValue XprType; 99 | typedef typename internal::traits::ReturnType PlainObject; 100 | typedef evaluator Base; 101 | 102 | EIGEN_DEVICE_FUNC explicit evaluator(const XprType& xpr) 103 | : m_result(xpr.rows(), xpr.cols()) 104 | { 105 | ::new (static_cast(this)) Base(m_result); 106 | xpr.evalTo(m_result); 107 | } 108 | 109 | protected: 110 | PlainObject m_result; 111 | }; 112 | 113 | } // end namespace internal 114 | 115 | } // end namespace Eigen 116 | 117 | #endif // EIGEN_RETURNBYVALUE_H 118 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/SolverBase.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 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_SOLVERBASE_H 11 | #define EIGEN_SOLVERBASE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | 18 | 19 | } // end namespace internal 20 | 21 | /** \class SolverBase 22 | * \brief A base class for matrix decomposition and solvers 23 | * 24 | * \tparam Derived the actual type of the decomposition/solver. 25 | * 26 | * Any matrix decomposition inheriting this base class provide the following API: 27 | * 28 | * \code 29 | * MatrixType A, b, x; 30 | * DecompositionType dec(A); 31 | * x = dec.solve(b); // solve A * x = b 32 | * x = dec.transpose().solve(b); // solve A^T * x = b 33 | * x = dec.adjoint().solve(b); // solve A' * x = b 34 | * \endcode 35 | * 36 | * \warning Currently, any other usage of transpose() and adjoint() are not supported and will produce compilation errors. 37 | * 38 | * \sa class PartialPivLU, class FullPivLU 39 | */ 40 | template 41 | class SolverBase : public EigenBase 42 | { 43 | public: 44 | 45 | typedef EigenBase Base; 46 | typedef typename internal::traits::Scalar Scalar; 47 | typedef Scalar CoeffReturnType; 48 | 49 | enum { 50 | RowsAtCompileTime = internal::traits::RowsAtCompileTime, 51 | ColsAtCompileTime = internal::traits::ColsAtCompileTime, 52 | SizeAtCompileTime = (internal::size_at_compile_time::RowsAtCompileTime, 53 | internal::traits::ColsAtCompileTime>::ret), 54 | MaxRowsAtCompileTime = internal::traits::MaxRowsAtCompileTime, 55 | MaxColsAtCompileTime = internal::traits::MaxColsAtCompileTime, 56 | MaxSizeAtCompileTime = (internal::size_at_compile_time::MaxRowsAtCompileTime, 57 | internal::traits::MaxColsAtCompileTime>::ret), 58 | IsVectorAtCompileTime = internal::traits::MaxRowsAtCompileTime == 1 59 | || internal::traits::MaxColsAtCompileTime == 1 60 | }; 61 | 62 | /** Default constructor */ 63 | SolverBase() 64 | {} 65 | 66 | ~SolverBase() 67 | {} 68 | 69 | using Base::derived; 70 | 71 | /** \returns an expression of the solution x of \f$ A x = b \f$ using the current decomposition of A. 72 | */ 73 | template 74 | inline const Solve 75 | solve(const MatrixBase& b) const 76 | { 77 | eigen_assert(derived().rows()==b.rows() && "solve(): invalid number of rows of the right hand side matrix b"); 78 | return Solve(derived(), b.derived()); 79 | } 80 | 81 | /** \internal the return type of transpose() */ 82 | typedef typename internal::add_const >::type ConstTransposeReturnType; 83 | /** \returns an expression of the transposed of the factored matrix. 84 | * 85 | * A typical usage is to solve for the transposed problem A^T x = b: 86 | * \code x = dec.transpose().solve(b); \endcode 87 | * 88 | * \sa adjoint(), solve() 89 | */ 90 | inline ConstTransposeReturnType transpose() const 91 | { 92 | return ConstTransposeReturnType(derived()); 93 | } 94 | 95 | /** \internal the return type of adjoint() */ 96 | typedef typename internal::conditional::IsComplex, 97 | CwiseUnaryOp, ConstTransposeReturnType>, 98 | ConstTransposeReturnType 99 | >::type AdjointReturnType; 100 | /** \returns an expression of the adjoint of the factored matrix 101 | * 102 | * A typical usage is to solve for the adjoint problem A' x = b: 103 | * \code x = dec.adjoint().solve(b); \endcode 104 | * 105 | * For real scalar types, this function is equivalent to transpose(). 106 | * 107 | * \sa transpose(), solve() 108 | */ 109 | inline AdjointReturnType adjoint() const 110 | { 111 | return AdjointReturnType(derived().transpose()); 112 | } 113 | 114 | protected: 115 | }; 116 | 117 | namespace internal { 118 | 119 | template 120 | struct generic_xpr_base 121 | { 122 | typedef SolverBase type; 123 | 124 | }; 125 | 126 | } // end namespace internal 127 | 128 | } // end namespace Eigen 129 | 130 | #endif // EIGEN_SOLVERBASE_H 131 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/Stride.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2010 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_STRIDE_H 11 | #define EIGEN_STRIDE_H 12 | 13 | namespace Eigen { 14 | 15 | /** \class Stride 16 | * \ingroup Core_Module 17 | * 18 | * \brief Holds strides information for Map 19 | * 20 | * This class holds the strides information for mapping arrays with strides with class Map. 21 | * 22 | * It holds two values: the inner stride and the outer stride. 23 | * 24 | * The inner stride is the pointer increment between two consecutive entries within a given row of a 25 | * row-major matrix or within a given column of a column-major matrix. 26 | * 27 | * The outer stride is the pointer increment between two consecutive rows of a row-major matrix or 28 | * between two consecutive columns of a column-major matrix. 29 | * 30 | * These two values can be passed either at compile-time as template parameters, or at runtime as 31 | * arguments to the constructor. 32 | * 33 | * Indeed, this class takes two template parameters: 34 | * \tparam _OuterStrideAtCompileTime the outer stride, or Dynamic if you want to specify it at runtime. 35 | * \tparam _InnerStrideAtCompileTime the inner stride, or Dynamic if you want to specify it at runtime. 36 | * 37 | * Here is an example: 38 | * \include Map_general_stride.cpp 39 | * Output: \verbinclude Map_general_stride.out 40 | * 41 | * \sa class InnerStride, class OuterStride, \ref TopicStorageOrders 42 | */ 43 | template 44 | class Stride 45 | { 46 | public: 47 | typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3 48 | enum { 49 | InnerStrideAtCompileTime = _InnerStrideAtCompileTime, 50 | OuterStrideAtCompileTime = _OuterStrideAtCompileTime 51 | }; 52 | 53 | /** Default constructor, for use when strides are fixed at compile time */ 54 | EIGEN_DEVICE_FUNC 55 | Stride() 56 | : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime) 57 | { 58 | eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic); 59 | } 60 | 61 | /** Constructor allowing to pass the strides at runtime */ 62 | EIGEN_DEVICE_FUNC 63 | Stride(Index outerStride, Index innerStride) 64 | : m_outer(outerStride), m_inner(innerStride) 65 | { 66 | eigen_assert(innerStride>=0 && outerStride>=0); 67 | } 68 | 69 | /** Copy constructor */ 70 | EIGEN_DEVICE_FUNC 71 | Stride(const Stride& other) 72 | : m_outer(other.outer()), m_inner(other.inner()) 73 | {} 74 | 75 | /** \returns the outer stride */ 76 | EIGEN_DEVICE_FUNC 77 | inline Index outer() const { return m_outer.value(); } 78 | /** \returns the inner stride */ 79 | EIGEN_DEVICE_FUNC 80 | inline Index inner() const { return m_inner.value(); } 81 | 82 | protected: 83 | internal::variable_if_dynamic m_outer; 84 | internal::variable_if_dynamic m_inner; 85 | }; 86 | 87 | /** \brief Convenience specialization of Stride to specify only an inner stride 88 | * See class Map for some examples */ 89 | template 90 | class InnerStride : public Stride<0, Value> 91 | { 92 | typedef Stride<0, Value> Base; 93 | public: 94 | EIGEN_DEVICE_FUNC InnerStride() : Base() {} 95 | EIGEN_DEVICE_FUNC InnerStride(Index v) : Base(0, v) {} // FIXME making this explicit could break valid code 96 | }; 97 | 98 | /** \brief Convenience specialization of Stride to specify only an outer stride 99 | * See class Map for some examples */ 100 | template 101 | class OuterStride : public Stride 102 | { 103 | typedef Stride Base; 104 | public: 105 | EIGEN_DEVICE_FUNC OuterStride() : Base() {} 106 | EIGEN_DEVICE_FUNC OuterStride(Index v) : Base(v,0) {} // FIXME making this explicit could break valid code 107 | }; 108 | 109 | } // end namespace Eigen 110 | 111 | #endif // EIGEN_STRIDE_H 112 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/arch/CUDA/Complex.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_COMPLEX_CUDA_H 11 | #define EIGEN_COMPLEX_CUDA_H 12 | 13 | // clang-format off 14 | 15 | namespace Eigen { 16 | 17 | namespace internal { 18 | 19 | #if defined(__CUDACC__) && defined(EIGEN_USE_GPU) 20 | 21 | // Many std::complex methods such as operator+, operator-, operator* and 22 | // operator/ are not constexpr. Due to this, clang does not treat them as device 23 | // functions and thus Eigen functors making use of these operators fail to 24 | // compile. Here, we manually specialize these functors for complex types when 25 | // building for CUDA to avoid non-constexpr methods. 26 | 27 | // Sum 28 | template struct scalar_sum_op, const std::complex > : binary_op_base, const std::complex > { 29 | typedef typename std::complex result_type; 30 | 31 | EIGEN_EMPTY_STRUCT_CTOR(scalar_sum_op) 32 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex operator() (const std::complex& a, const std::complex& b) const { 33 | return std::complex(numext::real(a) + numext::real(b), 34 | numext::imag(a) + numext::imag(b)); 35 | } 36 | }; 37 | 38 | template struct scalar_sum_op, std::complex > : scalar_sum_op, const std::complex > {}; 39 | 40 | 41 | // Difference 42 | template struct scalar_difference_op, const std::complex > : binary_op_base, const std::complex > { 43 | typedef typename std::complex result_type; 44 | 45 | EIGEN_EMPTY_STRUCT_CTOR(scalar_difference_op) 46 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex operator() (const std::complex& a, const std::complex& b) const { 47 | return std::complex(numext::real(a) - numext::real(b), 48 | numext::imag(a) - numext::imag(b)); 49 | } 50 | }; 51 | 52 | template struct scalar_difference_op, std::complex > : scalar_difference_op, const std::complex > {}; 53 | 54 | 55 | // Product 56 | template struct scalar_product_op, const std::complex > : binary_op_base, const std::complex > { 57 | enum { 58 | Vectorizable = packet_traits>::HasMul 59 | }; 60 | typedef typename std::complex result_type; 61 | 62 | EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op) 63 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex operator() (const std::complex& a, const std::complex& b) const { 64 | const T a_real = numext::real(a); 65 | const T a_imag = numext::imag(a); 66 | const T b_real = numext::real(b); 67 | const T b_imag = numext::imag(b); 68 | return std::complex(a_real * b_real - a_imag * b_imag, 69 | a_real * b_imag + a_imag * b_real); 70 | } 71 | }; 72 | 73 | template struct scalar_product_op, std::complex > : scalar_product_op, const std::complex > {}; 74 | 75 | 76 | // Quotient 77 | template struct scalar_quotient_op, const std::complex > : binary_op_base, const std::complex > { 78 | enum { 79 | Vectorizable = packet_traits>::HasDiv 80 | }; 81 | typedef typename std::complex result_type; 82 | 83 | EIGEN_EMPTY_STRUCT_CTOR(scalar_quotient_op) 84 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::complex operator() (const std::complex& a, const std::complex& b) const { 85 | const T a_real = numext::real(a); 86 | const T a_imag = numext::imag(a); 87 | const T b_real = numext::real(b); 88 | const T b_imag = numext::imag(b); 89 | const T norm = T(1) / (b_real * b_real + b_imag * b_imag); 90 | return std::complex((a_real * b_real + a_imag * b_imag) * norm, 91 | (a_imag * b_real - a_real * b_imag) * norm); 92 | } 93 | }; 94 | 95 | template struct scalar_quotient_op, std::complex > : scalar_quotient_op, const std::complex > {}; 96 | 97 | #endif 98 | 99 | } // end namespace internal 100 | 101 | } // end namespace Eigen 102 | 103 | #endif // EIGEN_COMPLEX_CUDA_H 104 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/arch/CUDA/TypeCasting.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2016 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_CUDA_H 11 | #define EIGEN_TYPE_CASTING_CUDA_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template<> 18 | struct scalar_cast_op { 19 | EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) 20 | typedef Eigen::half result_type; 21 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const float& a) const { 22 | #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 23 | return __float2half(a); 24 | #else 25 | return Eigen::half(a); 26 | #endif 27 | } 28 | }; 29 | 30 | template<> 31 | struct functor_traits > 32 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 33 | 34 | 35 | template<> 36 | struct scalar_cast_op { 37 | EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) 38 | typedef Eigen::half result_type; 39 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Eigen::half operator() (const int& a) const { 40 | #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 41 | return __float2half(static_cast(a)); 42 | #else 43 | return Eigen::half(static_cast(a)); 44 | #endif 45 | } 46 | }; 47 | 48 | template<> 49 | struct functor_traits > 50 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 51 | 52 | 53 | template<> 54 | struct scalar_cast_op { 55 | EIGEN_EMPTY_STRUCT_CTOR(scalar_cast_op) 56 | typedef float result_type; 57 | EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float operator() (const Eigen::half& a) const { 58 | #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 59 | return __half2float(a); 60 | #else 61 | return static_cast(a); 62 | #endif 63 | } 64 | }; 65 | 66 | template<> 67 | struct functor_traits > 68 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 69 | 70 | 71 | 72 | #if defined(EIGEN_HAS_CUDA_FP16) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 300 73 | 74 | template <> 75 | struct type_casting_traits { 76 | enum { 77 | VectorizedCast = 1, 78 | SrcCoeffRatio = 2, 79 | TgtCoeffRatio = 1 80 | }; 81 | }; 82 | 83 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float4 pcast(const half2& a, const half2& b) { 84 | float2 r1 = __half22float2(a); 85 | float2 r2 = __half22float2(b); 86 | return make_float4(r1.x, r1.y, r2.x, r2.y); 87 | } 88 | 89 | template <> 90 | struct type_casting_traits { 91 | enum { 92 | VectorizedCast = 1, 93 | SrcCoeffRatio = 1, 94 | TgtCoeffRatio = 2 95 | }; 96 | }; 97 | 98 | template<> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE half2 pcast(const float4& a) { 99 | // Simply discard the second half of the input 100 | return __floats2half2_rn(a.x, a.y); 101 | } 102 | 103 | #elif defined EIGEN_VECTORIZE_AVX512 104 | template <> 105 | struct type_casting_traits { 106 | enum { 107 | VectorizedCast = 1, 108 | SrcCoeffRatio = 1, 109 | TgtCoeffRatio = 1 110 | }; 111 | }; 112 | 113 | template<> EIGEN_STRONG_INLINE Packet16f pcast(const Packet16h& a) { 114 | return half2float(a); 115 | } 116 | 117 | template <> 118 | struct type_casting_traits { 119 | enum { 120 | VectorizedCast = 1, 121 | SrcCoeffRatio = 1, 122 | TgtCoeffRatio = 1 123 | }; 124 | }; 125 | 126 | template<> EIGEN_STRONG_INLINE Packet16h pcast(const Packet16f& a) { 127 | return float2half(a); 128 | } 129 | 130 | #elif defined EIGEN_VECTORIZE_AVX 131 | 132 | template <> 133 | struct type_casting_traits { 134 | enum { 135 | VectorizedCast = 1, 136 | SrcCoeffRatio = 1, 137 | TgtCoeffRatio = 1 138 | }; 139 | }; 140 | 141 | template<> EIGEN_STRONG_INLINE Packet8f pcast(const Packet8h& a) { 142 | return half2float(a); 143 | } 144 | 145 | template <> 146 | struct type_casting_traits { 147 | enum { 148 | VectorizedCast = 1, 149 | SrcCoeffRatio = 1, 150 | TgtCoeffRatio = 1 151 | }; 152 | }; 153 | 154 | template<> EIGEN_STRONG_INLINE Packet8h pcast(const Packet8f& a) { 155 | return float2half(a); 156 | } 157 | 158 | // Disable the following code since it's broken on too many platforms / compilers. 159 | //#elif defined(EIGEN_VECTORIZE_SSE) && (!EIGEN_ARCH_x86_64) && (!EIGEN_COMP_MSVC) 160 | #elif 0 161 | 162 | template <> 163 | struct type_casting_traits { 164 | enum { 165 | VectorizedCast = 1, 166 | SrcCoeffRatio = 1, 167 | TgtCoeffRatio = 1 168 | }; 169 | }; 170 | 171 | template<> EIGEN_STRONG_INLINE Packet4f pcast(const Packet4h& a) { 172 | __int64_t a64 = _mm_cvtm64_si64(a.x); 173 | Eigen::half h = raw_uint16_to_half(static_cast(a64)); 174 | float f1 = static_cast(h); 175 | h = raw_uint16_to_half(static_cast(a64 >> 16)); 176 | float f2 = static_cast(h); 177 | h = raw_uint16_to_half(static_cast(a64 >> 32)); 178 | float f3 = static_cast(h); 179 | h = raw_uint16_to_half(static_cast(a64 >> 48)); 180 | float f4 = static_cast(h); 181 | return _mm_set_ps(f4, f3, f2, f1); 182 | } 183 | 184 | template <> 185 | struct type_casting_traits { 186 | enum { 187 | VectorizedCast = 1, 188 | SrcCoeffRatio = 1, 189 | TgtCoeffRatio = 1 190 | }; 191 | }; 192 | 193 | template<> EIGEN_STRONG_INLINE Packet4h pcast(const Packet4f& a) { 194 | EIGEN_ALIGN16 float aux[4]; 195 | pstore(aux, a); 196 | Eigen::half h0(aux[0]); 197 | Eigen::half h1(aux[1]); 198 | Eigen::half h2(aux[2]); 199 | Eigen::half h3(aux[3]); 200 | 201 | Packet4h result; 202 | result.x = _mm_set_pi16(h3.x, h2.x, h1.x, h0.x); 203 | return result; 204 | } 205 | 206 | #endif 207 | 208 | } // end namespace internal 209 | 210 | } // end namespace Eigen 211 | 212 | #endif // EIGEN_TYPE_CASTING_CUDA_H 213 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/arch/ZVector/MathFunctions.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2007 Julien Pommier 5 | // Copyright (C) 2009 Gael Guennebaud 6 | // Copyright (C) 2016 Konstantinos Margaritis 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 | /* The sin, cos, exp, and log functions of this file come from 13 | * Julien Pommier's sse math library: http://gruntthepeon.free.fr/ssemath/ 14 | */ 15 | 16 | #ifndef EIGEN_MATH_FUNCTIONS_ALTIVEC_H 17 | #define EIGEN_MATH_FUNCTIONS_ALTIVEC_H 18 | 19 | namespace Eigen { 20 | 21 | namespace internal { 22 | 23 | static _EIGEN_DECLARE_CONST_Packet2d(1 , 1.0); 24 | static _EIGEN_DECLARE_CONST_Packet2d(2 , 2.0); 25 | static _EIGEN_DECLARE_CONST_Packet2d(half, 0.5); 26 | 27 | static _EIGEN_DECLARE_CONST_Packet2d(exp_hi, 709.437); 28 | static _EIGEN_DECLARE_CONST_Packet2d(exp_lo, -709.436139303); 29 | 30 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_LOG2EF, 1.4426950408889634073599); 31 | 32 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p0, 1.26177193074810590878e-4); 33 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p1, 3.02994407707441961300e-2); 34 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_p2, 9.99999999999999999910e-1); 35 | 36 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q0, 3.00198505138664455042e-6); 37 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q1, 2.52448340349684104192e-3); 38 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q2, 2.27265548208155028766e-1); 39 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_q3, 2.00000000000000000009e0); 40 | 41 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C1, 0.693145751953125); 42 | static _EIGEN_DECLARE_CONST_Packet2d(cephes_exp_C2, 1.42860682030941723212e-6); 43 | 44 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 45 | Packet2d pexp(const Packet2d& _x) 46 | { 47 | Packet2d x = _x; 48 | 49 | Packet2d tmp, fx; 50 | Packet2l emm0; 51 | 52 | // clamp x 53 | x = pmax(pmin(x, p2d_exp_hi), p2d_exp_lo); 54 | /* express exp(x) as exp(g + n*log(2)) */ 55 | fx = pmadd(p2d_cephes_LOG2EF, x, p2d_half); 56 | 57 | fx = vec_floor(fx); 58 | 59 | tmp = pmul(fx, p2d_cephes_exp_C1); 60 | Packet2d z = pmul(fx, p2d_cephes_exp_C2); 61 | x = psub(x, tmp); 62 | x = psub(x, z); 63 | 64 | Packet2d x2 = pmul(x,x); 65 | 66 | Packet2d px = p2d_cephes_exp_p0; 67 | px = pmadd(px, x2, p2d_cephes_exp_p1); 68 | px = pmadd(px, x2, p2d_cephes_exp_p2); 69 | px = pmul (px, x); 70 | 71 | Packet2d qx = p2d_cephes_exp_q0; 72 | qx = pmadd(qx, x2, p2d_cephes_exp_q1); 73 | qx = pmadd(qx, x2, p2d_cephes_exp_q2); 74 | qx = pmadd(qx, x2, p2d_cephes_exp_q3); 75 | 76 | x = pdiv(px,psub(qx,px)); 77 | x = pmadd(p2d_2,x,p2d_1); 78 | 79 | // build 2^n 80 | emm0 = vec_ctsl(fx, 0); 81 | 82 | static const Packet2l p2l_1023 = { 1023, 1023 }; 83 | static const Packet2ul p2ul_52 = { 52, 52 }; 84 | 85 | emm0 = emm0 + p2l_1023; 86 | emm0 = emm0 << reinterpret_cast(p2ul_52); 87 | 88 | // Altivec's max & min operators just drop silent NaNs. Check NaNs in 89 | // inputs and return them unmodified. 90 | Packet2ul isnumber_mask = reinterpret_cast(vec_cmpeq(_x, _x)); 91 | return vec_sel(_x, pmax(pmul(x, reinterpret_cast(emm0)), _x), 92 | isnumber_mask); 93 | } 94 | 95 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 96 | Packet4f pexp(const Packet4f& x) 97 | { 98 | Packet4f res; 99 | res.v4f[0] = pexp(x.v4f[0]); 100 | res.v4f[1] = pexp(x.v4f[1]); 101 | return res; 102 | } 103 | 104 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 105 | Packet2d psqrt(const Packet2d& x) 106 | { 107 | return __builtin_s390_vfsqdb(x); 108 | } 109 | 110 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 111 | Packet4f psqrt(const Packet4f& x) 112 | { 113 | Packet4f res; 114 | res.v4f[0] = psqrt(x.v4f[0]); 115 | res.v4f[1] = psqrt(x.v4f[1]); 116 | return res; 117 | } 118 | 119 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 120 | Packet2d prsqrt(const Packet2d& x) { 121 | // Unfortunately we can't use the much faster mm_rqsrt_pd since it only provides an approximation. 122 | return pset1(1.0) / psqrt(x); 123 | } 124 | 125 | template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED 126 | Packet4f prsqrt(const Packet4f& x) { 127 | Packet4f res; 128 | res.v4f[0] = prsqrt(x.v4f[0]); 129 | res.v4f[1] = prsqrt(x.v4f[1]); 130 | return res; 131 | } 132 | 133 | } // end namespace internal 134 | 135 | } // end namespace Eigen 136 | 137 | #endif // EIGEN_MATH_FUNCTIONS_ALTIVEC_H 138 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/functors/StlFunctors.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 | // 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_STL_FUNCTORS_H 11 | #define EIGEN_STL_FUNCTORS_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | // default functor traits for STL functors: 18 | 19 | template 20 | struct functor_traits > 21 | { enum { Cost = NumTraits::MulCost, PacketAccess = false }; }; 22 | 23 | template 24 | struct functor_traits > 25 | { enum { Cost = NumTraits::MulCost, PacketAccess = false }; }; 26 | 27 | template 28 | struct functor_traits > 29 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 30 | 31 | template 32 | struct functor_traits > 33 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 34 | 35 | template 36 | struct functor_traits > 37 | { enum { Cost = NumTraits::AddCost, PacketAccess = false }; }; 38 | 39 | template 40 | struct functor_traits > 41 | { enum { Cost = 1, PacketAccess = false }; }; 42 | 43 | template 44 | struct functor_traits > 45 | { enum { Cost = 1, PacketAccess = false }; }; 46 | 47 | template 48 | struct functor_traits > 49 | { enum { Cost = 1, PacketAccess = false }; }; 50 | 51 | template 52 | struct functor_traits > 53 | { enum { Cost = 1, PacketAccess = false }; }; 54 | 55 | template 56 | struct functor_traits > 57 | { enum { Cost = 1, PacketAccess = false }; }; 58 | 59 | template 60 | struct functor_traits > 61 | { enum { Cost = 1, PacketAccess = false }; }; 62 | 63 | template 64 | struct functor_traits > 65 | { enum { Cost = 1, PacketAccess = false }; }; 66 | 67 | template 68 | struct functor_traits > 69 | { enum { Cost = 1, PacketAccess = false }; }; 70 | 71 | template 72 | struct functor_traits > 73 | { enum { Cost = 1, PacketAccess = false }; }; 74 | 75 | #if (__cplusplus < 201103L) && (EIGEN_COMP_MSVC <= 1900) 76 | // std::binder* are deprecated since c++11 and will be removed in c++17 77 | template 78 | struct functor_traits > 79 | { enum { Cost = functor_traits::Cost, PacketAccess = false }; }; 80 | 81 | template 82 | struct functor_traits > 83 | { enum { Cost = functor_traits::Cost, PacketAccess = false }; }; 84 | #endif 85 | 86 | template 87 | struct functor_traits > 88 | { enum { Cost = 1 + functor_traits::Cost, PacketAccess = false }; }; 89 | 90 | template 91 | struct functor_traits > 92 | { enum { Cost = 1 + functor_traits::Cost, PacketAccess = false }; }; 93 | 94 | #ifdef EIGEN_STDEXT_SUPPORT 95 | 96 | template 97 | struct functor_traits > 98 | { enum { Cost = 0, PacketAccess = false }; }; 99 | 100 | template 101 | struct functor_traits > 102 | { enum { Cost = 0, PacketAccess = false }; }; 103 | 104 | template 105 | struct functor_traits > > 106 | { enum { Cost = 0, PacketAccess = false }; }; 107 | 108 | template 109 | struct functor_traits > > 110 | { enum { Cost = 0, PacketAccess = false }; }; 111 | 112 | template 113 | struct functor_traits > 114 | { enum { Cost = functor_traits::Cost + functor_traits::Cost, PacketAccess = false }; }; 115 | 116 | template 117 | struct functor_traits > 118 | { enum { Cost = functor_traits::Cost + functor_traits::Cost + functor_traits::Cost, PacketAccess = false }; }; 119 | 120 | #endif // EIGEN_STDEXT_SUPPORT 121 | 122 | // allow to add new functors and specializations of functor_traits from outside Eigen. 123 | // this macro is really needed because functor_traits must be specialized after it is declared but before it is used... 124 | #ifdef EIGEN_FUNCTORS_PLUGIN 125 | #include EIGEN_FUNCTORS_PLUGIN 126 | #endif 127 | 128 | } // end namespace internal 129 | 130 | } // end namespace Eigen 131 | 132 | #endif // EIGEN_STL_FUNCTORS_H 133 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.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 BLAS F77 29 | * General matrix-matrix product functionality based on ?GEMM. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H 34 | #define EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /********************************************************************** 41 | * This file implements general matrix-matrix multiplication using BLAS 42 | * gemm function via partial specialization of 43 | * general_matrix_matrix_product::run(..) method for float, double, 44 | * std::complex and std::complex types 45 | **********************************************************************/ 46 | 47 | // gemm specialization 48 | 49 | #define GEMM_SPECIALIZATION(EIGTYPE, EIGPREFIX, BLASTYPE, BLASPREFIX) \ 50 | template< \ 51 | typename Index, \ 52 | int LhsStorageOrder, bool ConjugateLhs, \ 53 | int RhsStorageOrder, bool ConjugateRhs> \ 54 | struct general_matrix_matrix_product \ 55 | { \ 56 | typedef gebp_traits Traits; \ 57 | \ 58 | static void run(Index rows, Index cols, Index depth, \ 59 | const EIGTYPE* _lhs, Index lhsStride, \ 60 | const EIGTYPE* _rhs, Index rhsStride, \ 61 | EIGTYPE* res, Index resStride, \ 62 | EIGTYPE alpha, \ 63 | level3_blocking& /*blocking*/, \ 64 | GemmParallelInfo* /*info = 0*/) \ 65 | { \ 66 | using std::conj; \ 67 | \ 68 | char transa, transb; \ 69 | BlasIndex m, n, k, lda, ldb, ldc; \ 70 | const EIGTYPE *a, *b; \ 71 | EIGTYPE beta(1); \ 72 | MatrixX##EIGPREFIX a_tmp, b_tmp; \ 73 | \ 74 | /* Set transpose options */ \ 75 | transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \ 76 | transb = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \ 77 | \ 78 | /* Set m, n, k */ \ 79 | m = convert_index(rows); \ 80 | n = convert_index(cols); \ 81 | k = convert_index(depth); \ 82 | \ 83 | /* Set lda, ldb, ldc */ \ 84 | lda = convert_index(lhsStride); \ 85 | ldb = convert_index(rhsStride); \ 86 | ldc = convert_index(resStride); \ 87 | \ 88 | /* Set a, b, c */ \ 89 | if ((LhsStorageOrder==ColMajor) && (ConjugateLhs)) { \ 90 | Map > lhs(_lhs,m,k,OuterStride<>(lhsStride)); \ 91 | a_tmp = lhs.conjugate(); \ 92 | a = a_tmp.data(); \ 93 | lda = convert_index(a_tmp.outerStride()); \ 94 | } else a = _lhs; \ 95 | \ 96 | if ((RhsStorageOrder==ColMajor) && (ConjugateRhs)) { \ 97 | Map > rhs(_rhs,k,n,OuterStride<>(rhsStride)); \ 98 | b_tmp = rhs.conjugate(); \ 99 | b = b_tmp.data(); \ 100 | ldb = convert_index(b_tmp.outerStride()); \ 101 | } else b = _rhs; \ 102 | \ 103 | BLASPREFIX##gemm_(&transa, &transb, &m, &n, &k, &numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, &numext::real_ref(beta), (BLASTYPE*)res, &ldc); \ 104 | }}; 105 | 106 | GEMM_SPECIALIZATION(double, d, double, d) 107 | GEMM_SPECIALIZATION(float, f, float, s) 108 | GEMM_SPECIALIZATION(dcomplex, cd, double, z) 109 | GEMM_SPECIALIZATION(scomplex, cf, float, c) 110 | 111 | } // end namespase internal 112 | 113 | } // end namespace Eigen 114 | 115 | #endif // EIGEN_GENERAL_MATRIX_MATRIX_BLAS_H 116 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/products/Parallelizer.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 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_PARALLELIZER_H 11 | #define EIGEN_PARALLELIZER_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /** \internal */ 18 | inline void manage_multi_threading(Action action, int* v) 19 | { 20 | static EIGEN_UNUSED int m_maxThreads = -1; 21 | 22 | if(action==SetAction) 23 | { 24 | eigen_internal_assert(v!=0); 25 | m_maxThreads = *v; 26 | } 27 | else if(action==GetAction) 28 | { 29 | eigen_internal_assert(v!=0); 30 | #ifdef EIGEN_HAS_OPENMP 31 | if(m_maxThreads>0) 32 | *v = m_maxThreads; 33 | else 34 | *v = omp_get_max_threads(); 35 | #else 36 | *v = 1; 37 | #endif 38 | } 39 | else 40 | { 41 | eigen_internal_assert(false); 42 | } 43 | } 44 | 45 | } 46 | 47 | /** Must be call first when calling Eigen from multiple threads */ 48 | inline void initParallel() 49 | { 50 | int nbt; 51 | internal::manage_multi_threading(GetAction, &nbt); 52 | std::ptrdiff_t l1, l2, l3; 53 | internal::manage_caching_sizes(GetAction, &l1, &l2, &l3); 54 | } 55 | 56 | /** \returns the max number of threads reserved for Eigen 57 | * \sa setNbThreads */ 58 | inline int nbThreads() 59 | { 60 | int ret; 61 | internal::manage_multi_threading(GetAction, &ret); 62 | return ret; 63 | } 64 | 65 | /** Sets the max number of threads reserved for Eigen 66 | * \sa nbThreads */ 67 | inline void setNbThreads(int v) 68 | { 69 | internal::manage_multi_threading(SetAction, &v); 70 | } 71 | 72 | namespace internal { 73 | 74 | template struct GemmParallelInfo 75 | { 76 | GemmParallelInfo() : sync(-1), users(0), lhs_start(0), lhs_length(0) {} 77 | 78 | Index volatile sync; 79 | int volatile users; 80 | 81 | Index lhs_start; 82 | Index lhs_length; 83 | }; 84 | 85 | template 86 | void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth, bool transpose) 87 | { 88 | // TODO when EIGEN_USE_BLAS is defined, 89 | // we should still enable OMP for other scalar types 90 | #if !(defined (EIGEN_HAS_OPENMP)) || defined (EIGEN_USE_BLAS) 91 | // FIXME the transpose variable is only needed to properly split 92 | // the matrix product when multithreading is enabled. This is a temporary 93 | // fix to support row-major destination matrices. This whole 94 | // parallelizer mechanism has to be redisigned anyway. 95 | EIGEN_UNUSED_VARIABLE(depth); 96 | EIGEN_UNUSED_VARIABLE(transpose); 97 | func(0,rows, 0,cols); 98 | #else 99 | 100 | // Dynamically check whether we should enable or disable OpenMP. 101 | // The conditions are: 102 | // - the max number of threads we can create is greater than 1 103 | // - we are not already in a parallel code 104 | // - the sizes are large enough 105 | 106 | // compute the maximal number of threads from the size of the product: 107 | // This first heuristic takes into account that the product kernel is fully optimized when working with nr columns at once. 108 | Index size = transpose ? rows : cols; 109 | Index pb_max_threads = std::max(1,size / Functor::Traits::nr); 110 | 111 | // compute the maximal number of threads from the total amount of work: 112 | double work = static_cast(rows) * static_cast(cols) * 113 | static_cast(depth); 114 | double kMinTaskSize = 50000; // FIXME improve this heuristic. 115 | pb_max_threads = std::max(1, std::min(pb_max_threads, work / kMinTaskSize)); 116 | 117 | // compute the number of threads we are going to use 118 | Index threads = std::min(nbThreads(), pb_max_threads); 119 | 120 | // if multi-threading is explicitely disabled, not useful, or if we already are in a parallel session, 121 | // then abort multi-threading 122 | // FIXME omp_get_num_threads()>1 only works for openmp, what if the user does not use openmp? 123 | if((!Condition) || (threads==1) || (omp_get_num_threads()>1)) 124 | return func(0,rows, 0,cols); 125 | 126 | Eigen::initParallel(); 127 | func.initParallelSession(threads); 128 | 129 | if(transpose) 130 | std::swap(rows,cols); 131 | 132 | ei_declare_aligned_stack_constructed_variable(GemmParallelInfo,info,threads,0); 133 | 134 | #pragma omp parallel num_threads(threads) 135 | { 136 | Index i = omp_get_thread_num(); 137 | // Note that the actual number of threads might be lower than the number of request ones. 138 | Index actual_threads = omp_get_num_threads(); 139 | 140 | Index blockCols = (cols / actual_threads) & ~Index(0x3); 141 | Index blockRows = (rows / actual_threads); 142 | blockRows = (blockRows/Functor::Traits::mr)*Functor::Traits::mr; 143 | 144 | Index r0 = i*blockRows; 145 | Index actualBlockRows = (i+1==actual_threads) ? rows-r0 : blockRows; 146 | 147 | Index c0 = i*blockCols; 148 | Index actualBlockCols = (i+1==actual_threads) ? cols-c0 : blockCols; 149 | 150 | info[i].lhs_start = r0; 151 | info[i].lhs_length = actualBlockRows; 152 | 153 | if(transpose) func(c0, actualBlockCols, 0, rows, info); 154 | else func(0, rows, c0, actualBlockCols, info); 155 | } 156 | #endif 157 | } 158 | 159 | } // end namespace internal 160 | 161 | } // end namespace Eigen 162 | 163 | #endif // EIGEN_PARALLELIZER_H 164 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/products/SelfadjointMatrixVector_BLAS.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 BLAS F77 29 | * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV. 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H 34 | #define EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H 35 | 36 | namespace Eigen { 37 | 38 | namespace internal { 39 | 40 | /********************************************************************** 41 | * This file implements selfadjoint matrix-vector multiplication using BLAS 42 | **********************************************************************/ 43 | 44 | // symv/hemv specialization 45 | 46 | template 47 | struct selfadjoint_matrix_vector_product_symv : 48 | selfadjoint_matrix_vector_product {}; 49 | 50 | #define EIGEN_BLAS_SYMV_SPECIALIZE(Scalar) \ 51 | template \ 52 | struct selfadjoint_matrix_vector_product { \ 53 | static void run( \ 54 | Index size, const Scalar* lhs, Index lhsStride, \ 55 | const Scalar* _rhs, Scalar* res, Scalar alpha) { \ 56 | enum {\ 57 | IsColMajor = StorageOrder==ColMajor \ 58 | }; \ 59 | if (IsColMajor == ConjugateLhs) {\ 60 | selfadjoint_matrix_vector_product::run( \ 61 | size, lhs, lhsStride, _rhs, res, alpha); \ 62 | } else {\ 63 | selfadjoint_matrix_vector_product_symv::run( \ 64 | size, lhs, lhsStride, _rhs, res, alpha); \ 65 | }\ 66 | } \ 67 | }; \ 68 | 69 | EIGEN_BLAS_SYMV_SPECIALIZE(double) 70 | EIGEN_BLAS_SYMV_SPECIALIZE(float) 71 | EIGEN_BLAS_SYMV_SPECIALIZE(dcomplex) 72 | EIGEN_BLAS_SYMV_SPECIALIZE(scomplex) 73 | 74 | #define EIGEN_BLAS_SYMV_SPECIALIZATION(EIGTYPE,BLASTYPE,BLASFUNC) \ 75 | template \ 76 | struct selfadjoint_matrix_vector_product_symv \ 77 | { \ 78 | typedef Matrix SYMVVector;\ 79 | \ 80 | static void run( \ 81 | Index size, const EIGTYPE* lhs, Index lhsStride, \ 82 | const EIGTYPE* _rhs, EIGTYPE* res, EIGTYPE alpha) \ 83 | { \ 84 | enum {\ 85 | IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \ 86 | IsLower = UpLo == Lower ? 1 : 0 \ 87 | }; \ 88 | BlasIndex n=convert_index(size), lda=convert_index(lhsStride), incx=1, incy=1; \ 89 | EIGTYPE beta(1); \ 90 | const EIGTYPE *x_ptr; \ 91 | char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \ 92 | SYMVVector x_tmp; \ 93 | if (ConjugateRhs) { \ 94 | Map map_x(_rhs,size,1); \ 95 | x_tmp=map_x.conjugate(); \ 96 | x_ptr=x_tmp.data(); \ 97 | } else x_ptr=_rhs; \ 98 | BLASFUNC(&uplo, &n, &numext::real_ref(alpha), (const BLASTYPE*)lhs, &lda, (const BLASTYPE*)x_ptr, &incx, &numext::real_ref(beta), (BLASTYPE*)res, &incy); \ 99 | }\ 100 | }; 101 | 102 | EIGEN_BLAS_SYMV_SPECIALIZATION(double, double, dsymv_) 103 | EIGEN_BLAS_SYMV_SPECIALIZATION(float, float, ssymv_) 104 | EIGEN_BLAS_SYMV_SPECIALIZATION(dcomplex, double, zhemv_) 105 | EIGEN_BLAS_SYMV_SPECIALIZATION(scomplex, float, chemv_) 106 | 107 | } // end namespace internal 108 | 109 | } // end namespace Eigen 110 | 111 | #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_BLAS_H 112 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/products/SelfadjointRank2Update.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_SELFADJOINTRANK2UPTADE_H 11 | #define EIGEN_SELFADJOINTRANK2UPTADE_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu' 18 | * It corresponds to the Level2 syr2 BLAS routine 19 | */ 20 | 21 | template 22 | struct selfadjoint_rank2_update_selector; 23 | 24 | template 25 | struct selfadjoint_rank2_update_selector 26 | { 27 | static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) 28 | { 29 | const Index size = u.size(); 30 | for (Index i=0; i >(mat+stride*i+i, size-i) += 33 | (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size-i) 34 | + (alpha * numext::conj(v.coeff(i))) * u.tail(size-i); 35 | } 36 | } 37 | }; 38 | 39 | template 40 | struct selfadjoint_rank2_update_selector 41 | { 42 | static void run(Scalar* mat, Index stride, const UType& u, const VType& v, const Scalar& alpha) 43 | { 44 | const Index size = u.size(); 45 | for (Index i=0; i >(mat+stride*i, i+1) += 47 | (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i+1) 48 | + (alpha * numext::conj(v.coeff(i))) * u.head(i+1); 49 | } 50 | }; 51 | 52 | template struct conj_expr_if 53 | : conditional::Scalar>,T> > {}; 55 | 56 | } // end namespace internal 57 | 58 | template 59 | template 60 | SelfAdjointView& SelfAdjointView 61 | ::rankUpdate(const MatrixBase& u, const MatrixBase& v, const Scalar& alpha) 62 | { 63 | typedef internal::blas_traits UBlasTraits; 64 | typedef typename UBlasTraits::DirectLinearAccessType ActualUType; 65 | typedef typename internal::remove_all::type _ActualUType; 66 | typename internal::add_const_on_value_type::type actualU = UBlasTraits::extract(u.derived()); 67 | 68 | typedef internal::blas_traits VBlasTraits; 69 | typedef typename VBlasTraits::DirectLinearAccessType ActualVType; 70 | typedef typename internal::remove_all::type _ActualVType; 71 | typename internal::add_const_on_value_type::type actualV = VBlasTraits::extract(v.derived()); 72 | 73 | // If MatrixType is row major, then we use the routine for lower triangular in the upper triangular case and 74 | // vice versa, and take the complex conjugate of all coefficients and vector entries. 75 | 76 | enum { IsRowMajor = (internal::traits::Flags&RowMajorBit) ? 1 : 0 }; 77 | Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived()) 78 | * numext::conj(VBlasTraits::extractScalarFactor(v.derived())); 79 | if (IsRowMajor) 80 | actualAlpha = numext::conj(actualAlpha); 81 | 82 | typedef typename internal::remove_all::type>::type UType; 83 | typedef typename internal::remove_all::type>::type VType; 84 | internal::selfadjoint_rank2_update_selector 86 | ::run(_expression().const_cast_derived().data(),_expression().outerStride(),UType(actualU),VType(actualV),actualAlpha); 87 | 88 | return *this; 89 | } 90 | 91 | } // end namespace Eigen 92 | 93 | #endif // EIGEN_SELFADJOINTRANK2UPTADE_H 94 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/products/TriangularSolverVector.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 | // 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_TRIANGULAR_SOLVER_VECTOR_H 11 | #define EIGEN_TRIANGULAR_SOLVER_VECTOR_H 12 | 13 | namespace Eigen { 14 | 15 | namespace internal { 16 | 17 | template 18 | struct triangular_solve_vector 19 | { 20 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 21 | { 22 | triangular_solve_vector::run(size, _lhs, lhsStride, rhs); 26 | } 27 | }; 28 | 29 | // forward and backward substitution, row-major, rhs is a vector 30 | template 31 | struct triangular_solve_vector 32 | { 33 | enum { 34 | IsLower = ((Mode&Lower)==Lower) 35 | }; 36 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 37 | { 38 | typedef Map, 0, OuterStride<> > LhsMap; 39 | const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); 40 | 41 | typedef const_blas_data_mapper LhsMapper; 42 | typedef const_blas_data_mapper RhsMapper; 43 | 44 | typename internal::conditional< 45 | Conjugate, 46 | const CwiseUnaryOp,LhsMap>, 47 | const LhsMap&> 48 | ::type cjLhs(lhs); 49 | static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; 50 | for(Index pi=IsLower ? 0 : size; 51 | IsLower ? pi0; 52 | IsLower ? pi+=PanelWidth : pi-=PanelWidth) 53 | { 54 | Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); 55 | 56 | Index r = IsLower ? pi : size - pi; // remaining size 57 | if (r > 0) 58 | { 59 | // let's directly call the low level product function because: 60 | // 1 - it is faster to compile 61 | // 2 - it is slighlty faster at runtime 62 | Index startRow = IsLower ? pi : pi-actualPanelWidth; 63 | Index startCol = IsLower ? 0 : pi; 64 | 65 | general_matrix_vector_product::run( 66 | actualPanelWidth, r, 67 | LhsMapper(&lhs.coeffRef(startRow,startCol), lhsStride), 68 | RhsMapper(rhs + startCol, 1), 69 | rhs + startRow, 1, 70 | RhsScalar(-1)); 71 | } 72 | 73 | for(Index k=0; k0) 78 | rhs[i] -= (cjLhs.row(i).segment(s,k).transpose().cwiseProduct(Map >(rhs+s,k))).sum(); 79 | 80 | if(!(Mode & UnitDiag)) 81 | rhs[i] /= cjLhs(i,i); 82 | } 83 | } 84 | } 85 | }; 86 | 87 | // forward and backward substitution, column-major, rhs is a vector 88 | template 89 | struct triangular_solve_vector 90 | { 91 | enum { 92 | IsLower = ((Mode&Lower)==Lower) 93 | }; 94 | static void run(Index size, const LhsScalar* _lhs, Index lhsStride, RhsScalar* rhs) 95 | { 96 | typedef Map, 0, OuterStride<> > LhsMap; 97 | const LhsMap lhs(_lhs,size,size,OuterStride<>(lhsStride)); 98 | typedef const_blas_data_mapper LhsMapper; 99 | typedef const_blas_data_mapper RhsMapper; 100 | typename internal::conditional,LhsMap>, 102 | const LhsMap& 103 | >::type cjLhs(lhs); 104 | static const Index PanelWidth = EIGEN_TUNE_TRIANGULAR_PANEL_WIDTH; 105 | 106 | for(Index pi=IsLower ? 0 : size; 107 | IsLower ? pi0; 108 | IsLower ? pi+=PanelWidth : pi-=PanelWidth) 109 | { 110 | Index actualPanelWidth = (std::min)(IsLower ? size - pi : pi, PanelWidth); 111 | Index startBlock = IsLower ? pi : pi-actualPanelWidth; 112 | Index endBlock = IsLower ? pi + actualPanelWidth : 0; 113 | 114 | for(Index k=0; k0) 123 | Map >(rhs+s,r) -= rhs[i] * cjLhs.col(i).segment(s,r); 124 | } 125 | Index r = IsLower ? size - endBlock : startBlock; // remaining size 126 | if (r > 0) 127 | { 128 | // let's directly call the low level product function because: 129 | // 1 - it is faster to compile 130 | // 2 - it is slighlty faster at runtime 131 | general_matrix_vector_product::run( 132 | r, actualPanelWidth, 133 | LhsMapper(&lhs.coeffRef(endBlock,startBlock), lhsStride), 134 | RhsMapper(rhs+startBlock, 1), 135 | rhs+endBlock, 1, RhsScalar(-1)); 136 | } 137 | } 138 | } 139 | }; 140 | 141 | } // end namespace internal 142 | 143 | } // end namespace Eigen 144 | 145 | #endif // EIGEN_TRIANGULAR_SOLVER_VECTOR_H 146 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/Core/util/MKL_support.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 Intel(R) MKL 29 | * Include file with common MKL declarations 30 | ******************************************************************************** 31 | */ 32 | 33 | #ifndef EIGEN_MKL_SUPPORT_H 34 | #define EIGEN_MKL_SUPPORT_H 35 | 36 | #ifdef EIGEN_USE_MKL_ALL 37 | #ifndef EIGEN_USE_BLAS 38 | #define EIGEN_USE_BLAS 39 | #endif 40 | #ifndef EIGEN_USE_LAPACKE 41 | #define EIGEN_USE_LAPACKE 42 | #endif 43 | #ifndef EIGEN_USE_MKL_VML 44 | #define EIGEN_USE_MKL_VML 45 | #endif 46 | #endif 47 | 48 | #ifdef EIGEN_USE_LAPACKE_STRICT 49 | #define EIGEN_USE_LAPACKE 50 | #endif 51 | 52 | #if defined(EIGEN_USE_MKL_VML) 53 | #define EIGEN_USE_MKL 54 | #endif 55 | 56 | #if defined EIGEN_USE_MKL 57 | # include 58 | /*Check IMKL version for compatibility: < 10.3 is not usable with Eigen*/ 59 | # ifndef INTEL_MKL_VERSION 60 | # undef EIGEN_USE_MKL /* INTEL_MKL_VERSION is not even defined on older versions */ 61 | # elif INTEL_MKL_VERSION < 100305 /* the intel-mkl-103-release-notes say this was when the lapacke.h interface was added*/ 62 | # undef EIGEN_USE_MKL 63 | # endif 64 | # ifndef EIGEN_USE_MKL 65 | /*If the MKL version is too old, undef everything*/ 66 | # undef EIGEN_USE_MKL_ALL 67 | # undef EIGEN_USE_LAPACKE 68 | # undef EIGEN_USE_MKL_VML 69 | # undef EIGEN_USE_LAPACKE_STRICT 70 | # undef EIGEN_USE_LAPACKE 71 | # endif 72 | #endif 73 | 74 | #if defined EIGEN_USE_MKL 75 | 76 | #define EIGEN_MKL_VML_THRESHOLD 128 77 | 78 | /* MKL_DOMAIN_BLAS, etc are defined only in 10.3 update 7 */ 79 | /* MKL_BLAS, etc are not defined in 11.2 */ 80 | #ifdef MKL_DOMAIN_ALL 81 | #define EIGEN_MKL_DOMAIN_ALL MKL_DOMAIN_ALL 82 | #else 83 | #define EIGEN_MKL_DOMAIN_ALL MKL_ALL 84 | #endif 85 | 86 | #ifdef MKL_DOMAIN_BLAS 87 | #define EIGEN_MKL_DOMAIN_BLAS MKL_DOMAIN_BLAS 88 | #else 89 | #define EIGEN_MKL_DOMAIN_BLAS MKL_BLAS 90 | #endif 91 | 92 | #ifdef MKL_DOMAIN_FFT 93 | #define EIGEN_MKL_DOMAIN_FFT MKL_DOMAIN_FFT 94 | #else 95 | #define EIGEN_MKL_DOMAIN_FFT MKL_FFT 96 | #endif 97 | 98 | #ifdef MKL_DOMAIN_VML 99 | #define EIGEN_MKL_DOMAIN_VML MKL_DOMAIN_VML 100 | #else 101 | #define EIGEN_MKL_DOMAIN_VML MKL_VML 102 | #endif 103 | 104 | #ifdef MKL_DOMAIN_PARDISO 105 | #define EIGEN_MKL_DOMAIN_PARDISO MKL_DOMAIN_PARDISO 106 | #else 107 | #define EIGEN_MKL_DOMAIN_PARDISO MKL_PARDISO 108 | #endif 109 | #endif 110 | 111 | namespace Eigen { 112 | 113 | typedef std::complex dcomplex; 114 | typedef std::complex scomplex; 115 | 116 | #if defined(EIGEN_USE_MKL) 117 | typedef MKL_INT BlasIndex; 118 | #else 119 | typedef int BlasIndex; 120 | #endif 121 | 122 | } // end namespace Eigen 123 | 124 | #if defined(EIGEN_USE_BLAS) 125 | #include "../../misc/blas.h" 126 | #endif 127 | 128 | #endif // EIGEN_MKL_SUPPORT_H 129 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h: -------------------------------------------------------------------------------- 1 | // This file is part of Eigen, a lightweight C++ template library 2 | // for linear algebra. 3 | // 4 | // Copyright (C) 2008-2016 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 a base class plugin containing common coefficient wise functions. 12 | 13 | /** \returns an expression of the difference of \c *this and \a other 14 | * 15 | * \note If you want to substract a given scalar from all coefficients, see Cwise::operator-(). 16 | * 17 | * \sa class CwiseBinaryOp, operator-=() 18 | */ 19 | EIGEN_MAKE_CWISE_BINARY_OP(operator-,difference) 20 | 21 | /** \returns an expression of the sum of \c *this and \a other 22 | * 23 | * \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). 24 | * 25 | * \sa class CwiseBinaryOp, operator+=() 26 | */ 27 | EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum) 28 | 29 | /** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other 30 | * 31 | * The template parameter \a CustomBinaryOp is the type of the functor 32 | * of the custom operator (see class CwiseBinaryOp for an example) 33 | * 34 | * Here is an example illustrating the use of custom functors: 35 | * \include class_CwiseBinaryOp.cpp 36 | * Output: \verbinclude class_CwiseBinaryOp.out 37 | * 38 | * \sa class CwiseBinaryOp, operator+(), operator-(), cwiseProduct() 39 | */ 40 | template 41 | EIGEN_DEVICE_FUNC 42 | EIGEN_STRONG_INLINE const CwiseBinaryOp 43 | binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other, const CustomBinaryOp& func = CustomBinaryOp()) const 44 | { 45 | return CwiseBinaryOp(derived(), other.derived(), func); 46 | } 47 | 48 | 49 | #ifndef EIGEN_PARSED_BY_DOXYGEN 50 | EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product) 51 | #else 52 | /** \returns an expression of \c *this scaled by the scalar factor \a scalar 53 | * 54 | * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 55 | */ 56 | template 57 | const CwiseBinaryOp,Derived,Constant > operator*(const T& scalar) const; 58 | /** \returns an expression of \a expr scaled by the scalar factor \a scalar 59 | * 60 | * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 61 | */ 62 | template friend 63 | const CwiseBinaryOp,Constant,Derived> operator*(const T& scalar, const StorageBaseType& expr); 64 | #endif 65 | 66 | 67 | 68 | #ifndef EIGEN_PARSED_BY_DOXYGEN 69 | EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(operator/,quotient) 70 | #else 71 | /** \returns an expression of \c *this divided by the scalar value \a scalar 72 | * 73 | * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 74 | */ 75 | template 76 | const CwiseBinaryOp,Derived,Constant > operator/(const T& scalar) const; 77 | #endif 78 | 79 | /** \returns an expression of the coefficient-wise boolean \b and operator of \c *this and \a other 80 | * 81 | * \warning this operator is for expression of bool only. 82 | * 83 | * Example: \include Cwise_boolean_and.cpp 84 | * Output: \verbinclude Cwise_boolean_and.out 85 | * 86 | * \sa operator||(), select() 87 | */ 88 | template 89 | EIGEN_DEVICE_FUNC 90 | inline const CwiseBinaryOp 91 | operator&&(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const 92 | { 93 | EIGEN_STATIC_ASSERT((internal::is_same::value && internal::is_same::value), 94 | THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); 95 | return CwiseBinaryOp(derived(),other.derived()); 96 | } 97 | 98 | /** \returns an expression of the coefficient-wise boolean \b or operator of \c *this and \a other 99 | * 100 | * \warning this operator is for expression of bool only. 101 | * 102 | * Example: \include Cwise_boolean_or.cpp 103 | * Output: \verbinclude Cwise_boolean_or.out 104 | * 105 | * \sa operator&&(), select() 106 | */ 107 | template 108 | EIGEN_DEVICE_FUNC 109 | inline const CwiseBinaryOp 110 | operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS &other) const 111 | { 112 | EIGEN_STATIC_ASSERT((internal::is_same::value && internal::is_same::value), 113 | THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); 114 | return CwiseBinaryOp(derived(),other.derived()); 115 | } 116 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/src/plugins/CommonCwiseUnaryOps.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 a base class plugin containing common coefficient wise functions. 12 | 13 | #ifndef EIGEN_PARSED_BY_DOXYGEN 14 | 15 | /** \internal the return type of conjugate() */ 16 | typedef typename internal::conditional::IsComplex, 17 | const CwiseUnaryOp, const Derived>, 18 | const Derived& 19 | >::type ConjugateReturnType; 20 | /** \internal the return type of real() const */ 21 | typedef typename internal::conditional::IsComplex, 22 | const CwiseUnaryOp, const Derived>, 23 | const Derived& 24 | >::type RealReturnType; 25 | /** \internal the return type of real() */ 26 | typedef typename internal::conditional::IsComplex, 27 | CwiseUnaryView, Derived>, 28 | Derived& 29 | >::type NonConstRealReturnType; 30 | /** \internal the return type of imag() const */ 31 | typedef CwiseUnaryOp, const Derived> ImagReturnType; 32 | /** \internal the return type of imag() */ 33 | typedef CwiseUnaryView, Derived> NonConstImagReturnType; 34 | 35 | typedef CwiseUnaryOp, const Derived> NegativeReturnType; 36 | 37 | #endif // not EIGEN_PARSED_BY_DOXYGEN 38 | 39 | /// \returns an expression of the opposite of \c *this 40 | /// 41 | EIGEN_DOC_UNARY_ADDONS(operator-,opposite) 42 | /// 43 | EIGEN_DEVICE_FUNC 44 | inline const NegativeReturnType 45 | operator-() const { return NegativeReturnType(derived()); } 46 | 47 | 48 | template struct CastXpr { typedef typename internal::cast_return_type, const Derived> >::type Type; }; 49 | 50 | /// \returns an expression of \c *this with the \a Scalar type casted to 51 | /// \a NewScalar. 52 | /// 53 | /// The template parameter \a NewScalar is the type we are casting the scalars to. 54 | /// 55 | EIGEN_DOC_UNARY_ADDONS(cast,conversion function) 56 | /// 57 | /// \sa class CwiseUnaryOp 58 | /// 59 | template 60 | EIGEN_DEVICE_FUNC 61 | typename CastXpr::Type 62 | cast() const 63 | { 64 | return typename CastXpr::Type(derived()); 65 | } 66 | 67 | /// \returns an expression of the complex conjugate of \c *this. 68 | /// 69 | EIGEN_DOC_UNARY_ADDONS(conjugate,complex conjugate) 70 | /// 71 | /// \sa Math functions, MatrixBase::adjoint() 72 | EIGEN_DEVICE_FUNC 73 | inline ConjugateReturnType 74 | conjugate() const 75 | { 76 | return ConjugateReturnType(derived()); 77 | } 78 | 79 | /// \returns a read-only expression of the real part of \c *this. 80 | /// 81 | EIGEN_DOC_UNARY_ADDONS(real,real part function) 82 | /// 83 | /// \sa imag() 84 | EIGEN_DEVICE_FUNC 85 | inline RealReturnType 86 | real() const { return RealReturnType(derived()); } 87 | 88 | /// \returns an read-only expression of the imaginary part of \c *this. 89 | /// 90 | EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function) 91 | /// 92 | /// \sa real() 93 | EIGEN_DEVICE_FUNC 94 | inline const ImagReturnType 95 | imag() const { return ImagReturnType(derived()); } 96 | 97 | /// \brief Apply a unary operator coefficient-wise 98 | /// \param[in] func Functor implementing the unary operator 99 | /// \tparam CustomUnaryOp Type of \a func 100 | /// \returns An expression of a custom coefficient-wise unary operator \a func of *this 101 | /// 102 | /// The function \c ptr_fun() from the C++ standard library can be used to make functors out of normal functions. 103 | /// 104 | /// Example: 105 | /// \include class_CwiseUnaryOp_ptrfun.cpp 106 | /// Output: \verbinclude class_CwiseUnaryOp_ptrfun.out 107 | /// 108 | /// Genuine functors allow for more possibilities, for instance it may contain a state. 109 | /// 110 | /// Example: 111 | /// \include class_CwiseUnaryOp.cpp 112 | /// Output: \verbinclude class_CwiseUnaryOp.out 113 | /// 114 | EIGEN_DOC_UNARY_ADDONS(unaryExpr,unary function) 115 | /// 116 | /// \sa unaryViewExpr, binaryExpr, class CwiseUnaryOp 117 | /// 118 | template 119 | EIGEN_DEVICE_FUNC 120 | inline const CwiseUnaryOp 121 | unaryExpr(const CustomUnaryOp& func = CustomUnaryOp()) const 122 | { 123 | return CwiseUnaryOp(derived(), func); 124 | } 125 | 126 | /// \returns an expression of a custom coefficient-wise unary operator \a func of *this 127 | /// 128 | /// The template parameter \a CustomUnaryOp is the type of the functor 129 | /// of the custom unary operator. 130 | /// 131 | /// Example: 132 | /// \include class_CwiseUnaryOp.cpp 133 | /// Output: \verbinclude class_CwiseUnaryOp.out 134 | /// 135 | EIGEN_DOC_UNARY_ADDONS(unaryViewExpr,unary function) 136 | /// 137 | /// \sa unaryExpr, binaryExpr class CwiseUnaryOp 138 | /// 139 | template 140 | EIGEN_DEVICE_FUNC 141 | inline const CwiseUnaryView 142 | unaryViewExpr(const CustomViewOp& func = CustomViewOp()) const 143 | { 144 | return CwiseUnaryView(derived(), func); 145 | } 146 | 147 | /// \returns a non const expression of the real part of \c *this. 148 | /// 149 | EIGEN_DOC_UNARY_ADDONS(real,real part function) 150 | /// 151 | /// \sa imag() 152 | EIGEN_DEVICE_FUNC 153 | inline NonConstRealReturnType 154 | real() { return NonConstRealReturnType(derived()); } 155 | 156 | /// \returns a non const expression of the imaginary part of \c *this. 157 | /// 158 | EIGEN_DOC_UNARY_ADDONS(imag,imaginary part function) 159 | /// 160 | /// \sa real() 161 | EIGEN_DEVICE_FUNC 162 | inline NonConstImagReturnType 163 | imag() { return NonConstImagReturnType(derived()); } 164 | -------------------------------------------------------------------------------- /third_party/eigen3/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 | -------------------------------------------------------------------------------- /third_party/utf8/utf8.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006 Nemanja Trifunovic 2 | 3 | /* 4 | Permission is hereby granted, free of charge, to any person or organization 5 | obtaining a copy of the software and accompanying documentation covered by 6 | this license (the "Software") to use, reproduce, display, distribute, 7 | execute, and transmit the Software, and to prepare derivative works of the 8 | Software, and to permit third-parties to whom the Software is furnished to 9 | do so, all subject to the following: 10 | 11 | The copyright notices in the Software and this entire statement, including 12 | the above license grant, this restriction and the following disclaimer, 13 | must be included in all copies of the Software, in whole or in part, and 14 | all derivative works of the Software, unless such copies or derivative 15 | works are solely in the form of machine-executable object code generated by 16 | a source language processor. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 | DEALINGS IN THE SOFTWARE. 25 | */ 26 | 27 | 28 | #ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 29 | #define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 30 | 31 | #include "utf8/checked.h" 32 | #include "utf8/unchecked.h" 33 | 34 | #endif // header guard 35 | --------------------------------------------------------------------------------