blob: a9b6978423fade7385c2bab0badcc6153b60bab3 [file] [log] [blame]
Brian Silverman72890c22015-09-19 14:37:37 -04001// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
Austin Schuh189376f2018-12-20 22:11:15 +11004// Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
Brian Silverman72890c22015-09-19 14:37:37 -04005//
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_BLAS_COMMON_H
11#define EIGEN_BLAS_COMMON_H
12
Austin Schuhc55b0172022-02-20 17:52:35 -080013#ifdef __GNUC__
14# if __GNUC__<5
15// GCC < 5.0 does not like the global Scalar typedef
16// we just keep shadow-warnings disabled permanently
17# define EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
18# endif
19#endif
20
Austin Schuh189376f2018-12-20 22:11:15 +110021#include "../Eigen/Core"
22#include "../Eigen/Jacobi"
Brian Silverman72890c22015-09-19 14:37:37 -040023
Brian Silverman72890c22015-09-19 14:37:37 -040024#include <complex>
25
26#ifndef SCALAR
27#error the token SCALAR must be defined to compile this file
28#endif
29
Austin Schuh189376f2018-12-20 22:11:15 +110030#include "../Eigen/src/misc/blas.h"
Brian Silverman72890c22015-09-19 14:37:37 -040031
32#define NOTR 0
33#define TR 1
34#define ADJ 2
35
36#define LEFT 0
37#define RIGHT 1
38
39#define UP 0
40#define LO 1
41
42#define NUNIT 0
43#define UNIT 1
44
45#define INVALID 0xff
46
47#define OP(X) ( ((X)=='N' || (X)=='n') ? NOTR \
48 : ((X)=='T' || (X)=='t') ? TR \
49 : ((X)=='C' || (X)=='c') ? ADJ \
50 : INVALID)
51
52#define SIDE(X) ( ((X)=='L' || (X)=='l') ? LEFT \
53 : ((X)=='R' || (X)=='r') ? RIGHT \
54 : INVALID)
55
56#define UPLO(X) ( ((X)=='U' || (X)=='u') ? UP \
57 : ((X)=='L' || (X)=='l') ? LO \
58 : INVALID)
59
60#define DIAG(X) ( ((X)=='N' || (X)=='n') ? NUNIT \
61 : ((X)=='U' || (X)=='u') ? UNIT \
62 : INVALID)
63
64
65inline bool check_op(const char* op)
66{
67 return OP(*op)!=0xff;
68}
69
70inline bool check_side(const char* side)
71{
72 return SIDE(*side)!=0xff;
73}
74
75inline bool check_uplo(const char* uplo)
76{
77 return UPLO(*uplo)!=0xff;
78}
79
80
81namespace Eigen {
82#include "BandTriangularSolver.h"
83#include "GeneralRank1Update.h"
84#include "PackedSelfadjointProduct.h"
85#include "PackedTriangularMatrixVector.h"
86#include "PackedTriangularSolverVector.h"
87#include "Rank2Update.h"
88}
89
90using namespace Eigen;
91
92typedef SCALAR Scalar;
93typedef NumTraits<Scalar>::Real RealScalar;
94typedef std::complex<RealScalar> Complex;
95
96enum
97{
98 IsComplex = Eigen::NumTraits<SCALAR>::IsComplex,
99 Conj = IsComplex
100};
101
102typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> PlainMatrixType;
103typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
Austin Schuh189376f2018-12-20 22:11:15 +1100104typedef Map<const Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > ConstMatrixType;
Brian Silverman72890c22015-09-19 14:37:37 -0400105typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
106typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
107
108template<typename T>
109Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
110matrix(T* data, int rows, int cols, int stride)
111{
112 return Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
113}
114
115template<typename T>
Austin Schuh189376f2018-12-20 22:11:15 +1100116Map<const Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
117matrix(const T* data, int rows, int cols, int stride)
118{
119 return Map<const Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
120}
121
122template<typename T>
123Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > make_vector(T* data, int size, int incr)
Brian Silverman72890c22015-09-19 14:37:37 -0400124{
125 return Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
126}
127
128template<typename T>
Austin Schuh189376f2018-12-20 22:11:15 +1100129Map<const Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > make_vector(const T* data, int size, int incr)
130{
131 return Map<const Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
132}
133
134template<typename T>
135Map<Matrix<T,Dynamic,1> > make_vector(T* data, int size)
Brian Silverman72890c22015-09-19 14:37:37 -0400136{
137 return Map<Matrix<T,Dynamic,1> >(data, size);
138}
139
140template<typename T>
Austin Schuh189376f2018-12-20 22:11:15 +1100141Map<const Matrix<T,Dynamic,1> > make_vector(const T* data, int size)
142{
143 return Map<const Matrix<T,Dynamic,1> >(data, size);
144}
145
146template<typename T>
Brian Silverman72890c22015-09-19 14:37:37 -0400147T* get_compact_vector(T* x, int n, int incx)
148{
149 if(incx==1)
150 return x;
151
Austin Schuh189376f2018-12-20 22:11:15 +1100152 typename Eigen::internal::remove_const<T>::type* ret = new Scalar[n];
153 if(incx<0) make_vector(ret,n) = make_vector(x,n,-incx).reverse();
154 else make_vector(ret,n) = make_vector(x,n, incx);
Brian Silverman72890c22015-09-19 14:37:37 -0400155 return ret;
156}
157
158template<typename T>
159T* copy_back(T* x_cpy, T* x, int n, int incx)
160{
161 if(x_cpy==x)
162 return 0;
163
Austin Schuh189376f2018-12-20 22:11:15 +1100164 if(incx<0) make_vector(x,n,-incx).reverse() = make_vector(x_cpy,n);
165 else make_vector(x,n, incx) = make_vector(x_cpy,n);
Brian Silverman72890c22015-09-19 14:37:37 -0400166 return x_cpy;
167}
168
Austin Schuhc55b0172022-02-20 17:52:35 -0800169#ifndef EIGEN_BLAS_FUNC_SUFFIX
170#define EIGEN_BLAS_FUNC_SUFFIX _
171#endif
172
173#define EIGEN_BLAS_FUNC(X) EIGEN_CAT(SCALAR_SUFFIX, EIGEN_CAT(X, EIGEN_BLAS_FUNC_SUFFIX))
Brian Silverman72890c22015-09-19 14:37:37 -0400174
175#endif // EIGEN_BLAS_COMMON_H