1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
6 // Copyright (C) 2020, Arm Limited and Contributors
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_CONSTANTS_H
13 #define EIGEN_CONSTANTS_H
14
15 namespace Eigen {
16
17 /** This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is
18 * stored in some runtime variable.
19 *
20 * Changing the value of Dynamic breaks the ABI, as Dynamic is often used as a template parameter for Matrix.
21 */
22 const int Dynamic = -1;
23
24 /** This value means that a signed quantity (e.g., a signed index) is not known at compile-time, and that instead its value
25 * has to be specified at runtime.
26 */
27 const int DynamicIndex = 0xffffff;
28
29 /** This value means that the increment to go from one value to another in a sequence is not constant for each step.
30 */
31 const int UndefinedIncr = 0xfffffe;
32
33 /** This value means +Infinity; it is currently used only as the p parameter to MatrixBase::lpNorm<int>().
34 * The value Infinity there means the L-infinity norm.
35 */
36 const int Infinity = -1;
37
38 /** This value means that the cost to evaluate an expression coefficient is either very expensive or
39 * cannot be known at compile time.
40 *
41 * This value has to be positive to (1) simplify cost computation, and (2) allow to distinguish between a very expensive and very very expensive expressions.
42 * It thus must also be large enough to make sure unrolling won't happen and that sub expressions will be evaluated, but not too large to avoid overflow.
43 */
44 const int HugeCost = 10000;
45
46 /** \defgroup flags Flags
47 * \ingroup Core_Module
48 *
49 * These are the possible bits which can be OR'ed to constitute the flags of a matrix or
50 * expression.
51 *
52 * It is important to note that these flags are a purely compile-time notion. They are a compile-time property of
53 * an expression type, implemented as enum's. They are not stored in memory at runtime, and they do not incur any
54 * runtime overhead.
55 *
56 * \sa MatrixBase::Flags
57 */
58
59 /** \ingroup flags
60 *
61 * for a matrix, this means that the storage order is row-major.
62 * If this bit is not set, the storage order is column-major.
63 * For an expression, this determines the storage order of
64 * the matrix created by evaluation of that expression.
65 * \sa \blank \ref TopicStorageOrders */
66 const unsigned int RowMajorBit = 0x1;
67
68 /** \ingroup flags
69 * means the expression should be evaluated by the calling expression */
70 const unsigned int EvalBeforeNestingBit = 0x2;
71
72 /** \ingroup flags
73 * \deprecated
74 * means the expression should be evaluated before any assignment */
75 EIGEN_DEPRECATED
76 const unsigned int EvalBeforeAssigningBit = 0x4; // FIXME deprecated
77
78 /** \ingroup flags
79 *
80 * Short version: means the expression might be vectorized
81 *
82 * Long version: means that the coefficients can be handled by packets
83 * and start at a memory location whose alignment meets the requirements
84 * of the present CPU architecture for optimized packet access. In the fixed-size
85 * case, there is the additional condition that it be possible to access all the
86 * coefficients by packets (this implies the requirement that the size be a multiple of 16 bytes,
87 * and that any nontrivial strides don't break the alignment). In the dynamic-size case,
88 * there is no such condition on the total size and strides, so it might not be possible to access
89 * all coeffs by packets.
90 *
91 * \note This bit can be set regardless of whether vectorization is actually enabled.
92 * To check for actual vectorizability, see \a ActualPacketAccessBit.
93 */
94 const unsigned int PacketAccessBit = 0x8;
95
96 #ifdef EIGEN_VECTORIZE
97 /** \ingroup flags
98 *
99 * If vectorization is enabled (EIGEN_VECTORIZE is defined) this constant
100 * is set to the value \a PacketAccessBit.
101 *
102 * If vectorization is not enabled (EIGEN_VECTORIZE is not defined) this constant
103 * is set to the value 0.
104 */
105 const unsigned int ActualPacketAccessBit = PacketAccessBit;
106 #else
107 const unsigned int ActualPacketAccessBit = 0x0;
108 #endif
109
110 /** \ingroup flags
111 *
112 * Short version: means the expression can be seen as 1D vector.
113 *
114 * Long version: means that one can access the coefficients
115 * of this expression by coeff(int), and coeffRef(int) in the case of a lvalue expression. These
116 * index-based access methods are guaranteed
117 * to not have to do any runtime computation of a (row, col)-pair from the index, so that it
118 * is guaranteed that whenever it is available, index-based access is at least as fast as
119 * (row,col)-based access. Expressions for which that isn't possible don't have the LinearAccessBit.
120 *
121 * If both PacketAccessBit and LinearAccessBit are set, then the
122 * packets of this expression can be accessed by packet(int), and writePacket(int) in the case of a
123 * lvalue expression.
124 *
125 * Typically, all vector expressions have the LinearAccessBit, but there is one exception:
126 * Product expressions don't have it, because it would be troublesome for vectorization, even when the
127 * Product is a vector expression. Thus, vector Product expressions allow index-based coefficient access but
128 * not index-based packet access, so they don't have the LinearAccessBit.
129 */
130 const unsigned int LinearAccessBit = 0x10;
131
132 /** \ingroup flags
133 *
134 * Means the expression has a coeffRef() method, i.e. is writable as its individual coefficients are directly addressable.
135 * This rules out read-only expressions.
136 *
137 * Note that DirectAccessBit and LvalueBit are mutually orthogonal, as there are examples of expression having one but note
138 * the other:
139 * \li writable expressions that don't have a very simple memory layout as a strided array, have LvalueBit but not DirectAccessBit
140 * \li Map-to-const expressions, for example Map<const Matrix>, have DirectAccessBit but not LvalueBit
141 *
142 * Expressions having LvalueBit also have their coeff() method returning a const reference instead of returning a new value.
143 */
144 const unsigned int LvalueBit = 0x20;
145
146 /** \ingroup flags
147 *
148 * Means that the underlying array of coefficients can be directly accessed as a plain strided array. The memory layout
149 * of the array of coefficients must be exactly the natural one suggested by rows(), cols(),
150 * outerStride(), innerStride(), and the RowMajorBit. This rules out expressions such as Diagonal, whose coefficients,
151 * though referencable, do not have such a regular memory layout.
152 *
153 * See the comment on LvalueBit for an explanation of how LvalueBit and DirectAccessBit are mutually orthogonal.
154 */
155 const unsigned int DirectAccessBit = 0x40;
156
157 /** \deprecated \ingroup flags
158 *
159 * means the first coefficient packet is guaranteed to be aligned.
160 * An expression cannot have the AlignedBit without the PacketAccessBit flag.
161 * In other words, this means we are allow to perform an aligned packet access to the first element regardless
162 * of the expression kind:
163 * \code
164 * expression.packet<Aligned>(0);
165 * \endcode
166 */
167 EIGEN_DEPRECATED const unsigned int AlignedBit = 0x80;
168
169 const unsigned int NestByRefBit = 0x100;
170
171 /** \ingroup flags
172 *
173 * for an expression, this means that the storage order
174 * can be either row-major or column-major.
175 * The precise choice will be decided at evaluation time or when
176 * combined with other expressions.
177 * \sa \blank \ref RowMajorBit, \ref TopicStorageOrders */
178 const unsigned int NoPreferredStorageOrderBit = 0x200;
179
180 /** \ingroup flags
181 *
182 * Means that the underlying coefficients can be accessed through pointers to the sparse (un)compressed storage format,
183 * that is, the expression provides:
184 * \code
185 inline const Scalar* valuePtr() const;
186 inline const Index* innerIndexPtr() const;
187 inline const Index* outerIndexPtr() const;
188 inline const Index* innerNonZeroPtr() const;
189 \endcode
190 */
191 const unsigned int CompressedAccessBit = 0x400;
192
193
194 // list of flags that are inherited by default
195 const unsigned int HereditaryBits = RowMajorBit
196 | EvalBeforeNestingBit;
197
198 /** \defgroup enums Enumerations
199 * \ingroup Core_Module
200 *
201 * Various enumerations used in %Eigen. Many of these are used as template parameters.
202 */
203
204 /** \ingroup enums
205 * Enum containing possible values for the \c Mode or \c UpLo parameter of
206 * MatrixBase::selfadjointView() and MatrixBase::triangularView(), and selfadjoint solvers. */
207 enum UpLoType {
208 /** View matrix as a lower triangular matrix. */
209 Lower=0x1,
210 /** View matrix as an upper triangular matrix. */
211 Upper=0x2,
212 /** %Matrix has ones on the diagonal; to be used in combination with #Lower or #Upper. */
213 UnitDiag=0x4,
214 /** %Matrix has zeros on the diagonal; to be used in combination with #Lower or #Upper. */
215 ZeroDiag=0x8,
216 /** View matrix as a lower triangular matrix with ones on the diagonal. */
217 UnitLower=UnitDiag|Lower,
218 /** View matrix as an upper triangular matrix with ones on the diagonal. */
219 UnitUpper=UnitDiag|Upper,
220 /** View matrix as a lower triangular matrix with zeros on the diagonal. */
221 StrictlyLower=ZeroDiag|Lower,
222 /** View matrix as an upper triangular matrix with zeros on the diagonal. */
223 StrictlyUpper=ZeroDiag|Upper,
224 /** Used in BandMatrix and SelfAdjointView to indicate that the matrix is self-adjoint. */
225 SelfAdjoint=0x10,
226 /** Used to support symmetric, non-selfadjoint, complex matrices. */
227 Symmetric=0x20
228 };
229
230 /** \ingroup enums
231 * Enum for indicating whether a buffer is aligned or not. */
232 enum AlignmentType {
233 Unaligned=0, /**< Data pointer has no specific alignment. */
234 Aligned8=8, /**< Data pointer is aligned on a 8 bytes boundary. */
235 Aligned16=16, /**< Data pointer is aligned on a 16 bytes boundary. */
236 Aligned32=32, /**< Data pointer is aligned on a 32 bytes boundary. */
237 Aligned64=64, /**< Data pointer is aligned on a 64 bytes boundary. */
238 Aligned128=128, /**< Data pointer is aligned on a 128 bytes boundary. */
239 AlignedMask=255,
240 Aligned=16, /**< \deprecated Synonym for Aligned16. */
241 #if EIGEN_MAX_ALIGN_BYTES==128
242 AlignedMax = Aligned128
243 #elif EIGEN_MAX_ALIGN_BYTES==64
244 AlignedMax = Aligned64
245 #elif EIGEN_MAX_ALIGN_BYTES==32
246 AlignedMax = Aligned32
247 #elif EIGEN_MAX_ALIGN_BYTES==16
248 AlignedMax = Aligned16
249 #elif EIGEN_MAX_ALIGN_BYTES==8
250 AlignedMax = Aligned8
251 #elif EIGEN_MAX_ALIGN_BYTES==0
252 AlignedMax = Unaligned
253 #else
254 #error Invalid value for EIGEN_MAX_ALIGN_BYTES
255 #endif
256 };
257
258 /** \ingroup enums
259 * Enum containing possible values for the \p Direction parameter of
260 * Reverse, PartialReduxExpr and VectorwiseOp. */
261 enum DirectionType {
262 /** For Reverse, all columns are reversed;
263 * for PartialReduxExpr and VectorwiseOp, act on columns. */
264 Vertical,
265 /** For Reverse, all rows are reversed;
266 * for PartialReduxExpr and VectorwiseOp, act on rows. */
267 Horizontal,
268 /** For Reverse, both rows and columns are reversed;
269 * not used for PartialReduxExpr and VectorwiseOp. */
270 BothDirections
271 };
272
273 /** \internal \ingroup enums
274 * Enum to specify how to traverse the entries of a matrix. */
275 enum TraversalType {
276 /** \internal Default traversal, no vectorization, no index-based access */
277 DefaultTraversal,
278 /** \internal No vectorization, use index-based access to have only one for loop instead of 2 nested loops */
279 LinearTraversal,
280 /** \internal Equivalent to a slice vectorization for fixed-size matrices having good alignment
281 * and good size */
282 InnerVectorizedTraversal,
283 /** \internal Vectorization path using a single loop plus scalar loops for the
284 * unaligned boundaries */
285 LinearVectorizedTraversal,
286 /** \internal Generic vectorization path using one vectorized loop per row/column with some
287 * scalar loops to handle the unaligned boundaries */
288 SliceVectorizedTraversal,
289 /** \internal Special case to properly handle incompatible scalar types or other defecting cases*/
290 InvalidTraversal,
291 /** \internal Evaluate all entries at once */
292 AllAtOnceTraversal
293 };
294
295 /** \internal \ingroup enums
296 * Enum to specify whether to unroll loops when traversing over the entries of a matrix. */
297 enum UnrollingType {
298 /** \internal Do not unroll loops. */
299 NoUnrolling,
300 /** \internal Unroll only the inner loop, but not the outer loop. */
301 InnerUnrolling,
302 /** \internal Unroll both the inner and the outer loop. If there is only one loop,
303 * because linear traversal is used, then unroll that loop. */
304 CompleteUnrolling
305 };
306
307 /** \internal \ingroup enums
308 * Enum to specify whether to use the default (built-in) implementation or the specialization. */
309 enum SpecializedType {
310 Specialized,
311 BuiltIn
312 };
313
314 /** \ingroup enums
315 * Enum containing possible values for the \p _Options template parameter of
316 * Matrix, Array and BandMatrix. */
317 enum StorageOptions {
318 /** Storage order is column major (see \ref TopicStorageOrders). */
319 ColMajor = 0,
320 /** Storage order is row major (see \ref TopicStorageOrders). */
321 RowMajor = 0x1, // it is only a coincidence that this is equal to RowMajorBit -- don't rely on that
322 /** Align the matrix itself if it is vectorizable fixed-size */
323 AutoAlign = 0,
324 /** Don't require alignment for the matrix itself (the array of coefficients, if dynamically allocated, may still be requested to be aligned) */ // FIXME --- clarify the situation
325 DontAlign = 0x2
326 };
327
328 /** \ingroup enums
329 * Enum for specifying whether to apply or solve on the left or right. */
330 enum SideType {
331 /** Apply transformation on the left. */
332 OnTheLeft = 1,
333 /** Apply transformation on the right. */
334 OnTheRight = 2
335 };
336
337 /** \ingroup enums
338 * Enum for specifying NaN-propagation behavior, e.g. for coeff-wise min/max. */
339 enum NaNPropagationOptions {
340 /** Implementation defined behavior if NaNs are present. */
341 PropagateFast = 0,
342 /** Always propagate NaNs. */
343 PropagateNaN,
344 /** Always propagate not-NaNs. */
345 PropagateNumbers
346 };
347
348 /* the following used to be written as:
349 *
350 * struct NoChange_t {};
351 * namespace {
352 * EIGEN_UNUSED NoChange_t NoChange;
353 * }
354 *
355 * on the ground that it feels dangerous to disambiguate overloaded functions on enum/integer types.
356 * However, this leads to "variable declared but never referenced" warnings on Intel Composer XE,
357 * and we do not know how to get rid of them (bug 450).
358 */
359
360 enum NoChange_t { NoChange };
361 enum Sequential_t { Sequential };
362 enum Default_t { Default };
363
364 /** \internal \ingroup enums
365 * Used in AmbiVector. */
366 enum AmbiVectorMode {
367 IsDense = 0,
368 IsSparse
369 };
370
371 /** \ingroup enums
372 * Used as template parameter in DenseCoeffBase and MapBase to indicate
373 * which accessors should be provided. */
374 enum AccessorLevels {
375 /** Read-only access via a member function. */
376 ReadOnlyAccessors,
377 /** Read/write access via member functions. */
378 WriteAccessors,
379 /** Direct read-only access to the coefficients. */
380 DirectAccessors,
381 /** Direct read/write access to the coefficients. */
382 DirectWriteAccessors
383 };
384
385 /** \ingroup enums
386 * Enum with options to give to various decompositions. */
387 enum DecompositionOptions {
388 /** \internal Not used (meant for LDLT?). */
389 Pivoting = 0x01,
390 /** \internal Not used (meant for LDLT?). */
391 NoPivoting = 0x02,
392 /** Used in JacobiSVD to indicate that the square matrix U is to be computed. */
393 ComputeFullU = 0x04,
394 /** Used in JacobiSVD to indicate that the thin matrix U is to be computed. */
395 ComputeThinU = 0x08,
396 /** Used in JacobiSVD to indicate that the square matrix V is to be computed. */
397 ComputeFullV = 0x10,
398 /** Used in JacobiSVD to indicate that the thin matrix V is to be computed. */
399 ComputeThinV = 0x20,
400 /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify
401 * that only the eigenvalues are to be computed and not the eigenvectors. */
402 EigenvaluesOnly = 0x40,
403 /** Used in SelfAdjointEigenSolver and GeneralizedSelfAdjointEigenSolver to specify
404 * that both the eigenvalues and the eigenvectors are to be computed. */
405 ComputeEigenvectors = 0x80,
406 /** \internal */
407 EigVecMask = EigenvaluesOnly | ComputeEigenvectors,
408 /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
409 * solve the generalized eigenproblem \f$ Ax = \lambda B x \f$. */
410 Ax_lBx = 0x100,
411 /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
412 * solve the generalized eigenproblem \f$ ABx = \lambda x \f$. */
413 ABx_lx = 0x200,
414 /** Used in GeneralizedSelfAdjointEigenSolver to indicate that it should
415 * solve the generalized eigenproblem \f$ BAx = \lambda x \f$. */
416 BAx_lx = 0x400,
417 /** \internal */
418 GenEigMask = Ax_lBx | ABx_lx | BAx_lx
419 };
420
421 /** \ingroup enums
422 * Possible values for the \p QRPreconditioner template parameter of JacobiSVD. */
423 enum QRPreconditioners {
424 /** Do not specify what is to be done if the SVD of a non-square matrix is asked for. */
425 NoQRPreconditioner,
426 /** Use a QR decomposition without pivoting as the first step. */
427 HouseholderQRPreconditioner,
428 /** Use a QR decomposition with column pivoting as the first step. */
429 ColPivHouseholderQRPreconditioner,
430 /** Use a QR decomposition with full pivoting as the first step. */
431 FullPivHouseholderQRPreconditioner
432 };
433
434 #ifdef Success
435 #error The preprocessor symbol 'Success' is defined, possibly by the X11 header file X.h
436 #endif
437
438 /** \ingroup enums
439 * Enum for reporting the status of a computation. */
440 enum ComputationInfo {
441 /** Computation was successful. */
442 Success = 0,
443 /** The provided data did not satisfy the prerequisites. */
444 NumericalIssue = 1,
445 /** Iterative procedure did not converge. */
446 NoConvergence = 2,
447 /** The inputs are invalid, or the algorithm has been improperly called.
448 * When assertions are enabled, such errors trigger an assert. */
449 InvalidInput = 3
450 };
451
452 /** \ingroup enums
453 * Enum used to specify how a particular transformation is stored in a matrix.
454 * \sa Transform, Hyperplane::transform(). */
455 enum TransformTraits {
456 /** Transformation is an isometry. */
457 Isometry = 0x1,
458 /** Transformation is an affine transformation stored as a (Dim+1)^2 matrix whose last row is
459 * assumed to be [0 ... 0 1]. */
460 Affine = 0x2,
461 /** Transformation is an affine transformation stored as a (Dim) x (Dim+1) matrix. */
462 AffineCompact = 0x10 | Affine,
463 /** Transformation is a general projective transformation stored as a (Dim+1)^2 matrix. */
464 Projective = 0x20
465 };
466
467 /** \internal \ingroup enums
468 * Enum used to choose between implementation depending on the computer architecture. */
469 namespace Architecture
470 {
471 enum Type {
472 Generic = 0x0,
473 SSE = 0x1,
474 AltiVec = 0x2,
475 VSX = 0x3,
476 NEON = 0x4,
477 MSA = 0x5,
478 SVE = 0x6,
479 #if defined EIGEN_VECTORIZE_SSE
480 Target = SSE
481 #elif defined EIGEN_VECTORIZE_ALTIVEC
482 Target = AltiVec
483 #elif defined EIGEN_VECTORIZE_VSX
484 Target = VSX
485 #elif defined EIGEN_VECTORIZE_NEON
486 Target = NEON
487 #elif defined EIGEN_VECTORIZE_SVE
488 Target = SVE
489 #elif defined EIGEN_VECTORIZE_MSA
490 Target = MSA
491 #else
492 Target = Generic
493 #endif
494 };
495 }
496
497 /** \internal \ingroup enums
498 * Enum used as template parameter in Product and product evaluators. */
499 enum ProductImplType
500 { DefaultProduct=0, LazyProduct, AliasFreeProduct, CoeffBasedProductMode, LazyCoeffBasedProductMode, OuterProduct, InnerProduct, GemvProduct, GemmProduct };
501
502 /** \internal \ingroup enums
503 * Enum used in experimental parallel implementation. */
504 enum Action {GetAction, SetAction};
505
506 /** The type used to identify a dense storage. */
507 struct Dense {};
508
509 /** The type used to identify a general sparse storage. */
510 struct Sparse {};
511
512 /** The type used to identify a general solver (factored) storage. */
513 struct SolverStorage {};
514
515 /** The type used to identify a permutation storage. */
516 struct PermutationStorage {};
517
518 /** The type used to identify a permutation storage. */
519 struct TranspositionsStorage {};
520
521 /** The type used to identify a matrix expression */
522 struct MatrixXpr {};
523
524 /** The type used to identify an array expression */
525 struct ArrayXpr {};
526
527 // An evaluator must define its shape. By default, it can be one of the following:
debugNameDenseShape528 struct DenseShape { static std::string debugName() { return "DenseShape"; } };
debugNameSolverShape529 struct SolverShape { static std::string debugName() { return "SolverShape"; } };
debugNameHomogeneousShape530 struct HomogeneousShape { static std::string debugName() { return "HomogeneousShape"; } };
debugNameDiagonalShape531 struct DiagonalShape { static std::string debugName() { return "DiagonalShape"; } };
debugNameBandShape532 struct BandShape { static std::string debugName() { return "BandShape"; } };
debugNameTriangularShape533 struct TriangularShape { static std::string debugName() { return "TriangularShape"; } };
debugNameSelfAdjointShape534 struct SelfAdjointShape { static std::string debugName() { return "SelfAdjointShape"; } };
debugNamePermutationShape535 struct PermutationShape { static std::string debugName() { return "PermutationShape"; } };
debugNameTranspositionsShape536 struct TranspositionsShape { static std::string debugName() { return "TranspositionsShape"; } };
debugNameSparseShape537 struct SparseShape { static std::string debugName() { return "SparseShape"; } };
538
539 namespace internal {
540
541 // random access iterators based on coeff*() accessors.
542 struct IndexBased {};
543
544 // evaluator based on iterators to access coefficients.
545 struct IteratorBased {};
546
547 /** \internal
548 * Constants for comparison functors
549 */
550 enum ComparisonName {
551 cmp_EQ = 0,
552 cmp_LT = 1,
553 cmp_LE = 2,
554 cmp_UNORD = 3,
555 cmp_NEQ = 4,
556 cmp_GT = 5,
557 cmp_GE = 6
558 };
559 } // end namespace internal
560
561 } // end namespace Eigen
562
563 #endif // EIGEN_CONSTANTS_H
564