xerus
a general purpose tensor library
blasLapackWrapper.h
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
25 #pragma once
26 
27 #include "misc/standard.h"
28 #include <memory>
29 
30 
31 namespace xerus {
37  namespace blasWrapper {
38 
39  //----------------------------------------------- LEVEL I BLAS ----------------------------------------------------------
40 
42  double one_norm(const double* const _x, const size_t _n);
43 
45  double two_norm(const double* const _x, const size_t _n);
46 
48  double dot_product(const double* const _x, const size_t _n, const double* const _y);
49 
50 
51  //----------------------------------------------- LEVEL II BLAS ---------------------------------------------------------
52 
54  void matrix_vector_product(double* const _x, const size_t _m, const double _alpha, const double* const _A, const size_t _n, const bool _transposed, const double* const _y);
55 
57  void dyadic_vector_product(double* _A, const size_t _m, const size_t _n, const double _alpha, const double*const _x, const double*const _y);
58 
59  //----------------------------------------------- LEVEL III BLAS --------------------------------------------------------
61  void matrix_matrix_product( double* const _C,
62  const size_t _leftDim,
63  const size_t _rightDim,
64  const double _alpha,
65  const double* const _A,
66  const size_t _lda,
67  const bool _transposeA,
68  const size_t _middleDim,
69  const double* const _B,
70  const size_t _ldb,
71  const bool _transposeB);
72 
74  static XERUS_force_inline void matrix_matrix_product( double* const _C,
75  const size_t _leftDim,
76  const size_t _rightDim,
77  const double _alpha,
78  const double* const _A,
79  const bool _transposeA,
80  const size_t _middleDim,
81  const double* const _B,
82  const bool _transposeB) {
83 
84  matrix_matrix_product( _C, _leftDim, _rightDim, _alpha, _A, _transposeA ? _leftDim : _middleDim, _transposeA, _middleDim, _B, _transposeB ? _middleDim : _rightDim, _transposeB);
85  }
86 
87  //----------------------------------------------- LAPACK ----------------------------------------------------------------
88 
90  void svd( double* const _U, double* const _S, double* const _Vt, const double* const _A, const size_t _m, const size_t _n);
91 
93  void svd_destructive( double* const _U, double* const _S, double* const _Vt, double* const _A, const size_t _m, const size_t _n);
94 
95 
97  std::tuple<std::unique_ptr<double[]>, std::unique_ptr<double[]>, size_t> qc(const double* const _A, const size_t _m, const size_t _n);
98 
100  std::tuple<std::unique_ptr<double[]>, std::unique_ptr<double[]>, size_t> qc_destructive(double* const _A, const size_t _m, const size_t _n);
101 
102 
104  std::tuple<std::unique_ptr<double[]>, std::unique_ptr<double[]>, size_t> cq(const double* const _A, const size_t _m, const size_t _n);
105 
107  std::tuple<std::unique_ptr<double[]>, std::unique_ptr<double[]>, size_t> cq_destructive(double* const _A, const size_t _m, const size_t _n);
108 
109 
111  void qr( double* const _Q, double* const _R, const double* const _A, const size_t _m, const size_t _n);
112 
114  void inplace_qr(double* const _AtoQ, double* const _R, const size_t _m, const size_t _n);
115 
117  void qr_destructive( double* const _Q, double* const _R, double* const _A, const size_t _m, const size_t _n);
118 
119 
120 
122  void rq( double* const _R, double* const _Q, const double* const _A, const size_t _m, const size_t _n);
123 
125  void inplace_rq( double* const _R, double* const _AtoQ, const size_t _m, const size_t _n);
126 
128  void rq_destructive( double* const _R, double* const _Q, double* const _A, const size_t _m, const size_t _n);
129 
130 
132  void solve(double* _x, const double* _A, size_t _m, size_t _n, const double* _b, size_t _p);
133 
134 
135 
137  void solve_least_squares( double* const _x, const double* const _A, const size_t _m, const size_t _n, const double* const _b, const size_t _p);
138 
140  void solve_least_squares_destructive( double* const _x, double* const _A, const size_t _m, const size_t _n, double* const _b, const size_t _p);
141 
142 
143 
145  void inverse( double* const _B, const double* const _A, const size_t _m, const size_t _n);
146  }
147 
148 }
std::tuple< std::unique_ptr< double[]>, std::unique_ptr< double[]>, size_t > cq(const double *const _A, const size_t _m, const size_t _n)
: splits A = C*Q, with _C an rxm matrix (where r is the rank of _A) and _Q orthogonal.
std::tuple< std::unique_ptr< double[]>, std::unique_ptr< double[]>, size_t > qc(const double *const _A, const size_t _m, const size_t _n)
: splits A = Q*C, with _C an rxn matrix (where r is the rank of _A) and _Q orthogonal.
void qr(double *const _Q, double *const _R, const double *const _A, const size_t _m, const size_t _n)
: Performs (Q,R) = QR(A)
void matrix_matrix_product(double *const _C, const size_t _leftDim, const size_t _rightDim, const double _alpha, const double *const _A, const size_t _lda, const bool _transposeA, const size_t _middleDim, const double *const _B, const size_t _ldb, const bool _transposeB)
: Performs the Matrix-Matrix product C = alpha*OP(A) * OP(B)
void inplace_rq(double *const _R, double *const _AtoQ, const size_t _m, const size_t _n)
: Performs (R,AtoQ) = RQ(AtoQ)
The main namespace of xerus.
Definition: basic.h:37
void inplace_qr(double *const _AtoQ, double *const _R, const size_t _m, const size_t _n)
: Performs (AtoQ,R) = QR(AtoQ)
void svd_destructive(double *const _U, double *const _S, double *const _Vt, double *const _A, const size_t _m, const size_t _n)
: Performs (U,S,V) = SVD(A). Destroys A.
void rq(double *const _R, double *const _Q, const double *const _A, const size_t _m, const size_t _n)
: Performs (R,Q) = RQ(A)
double dot_product(const double *const _x, const size_t _n, const double *const _y)
: Computes the dot product = x^T*y
double one_norm(const double *const _x, const size_t _n)
: Computes the one norm =||x||_1
void dyadic_vector_product(double *_A, const size_t _m, const size_t _n, const double _alpha, const double *const _x, const double *const _y)
: Performs A = alpha*x*y^T
std::tuple< std::unique_ptr< double[]>, std::unique_ptr< double[]>, size_t > qc_destructive(double *const _A, const size_t _m, const size_t _n)
: splits A = Q*C, with _C an rxn matrix (where r is the rank of _A) and _Q orthogonal. Destroys A.
void solve(double *_x, const double *_A, size_t _m, size_t _n, const double *_b, size_t _p)
: Solves Ax = b for x
double two_norm(const double *const _x, const size_t _n)
: Computes the two norm =||x||_2
void qr_destructive(double *const _Q, double *const _R, double *const _A, const size_t _m, const size_t _n)
: Performs (Q,R) = QR(A), destroys A in the process
void svd(double *const _U, double *const _S, double *const _Vt, const double *const _A, const size_t _m, const size_t _n)
: Performs (U,S,V) = SVD(A)
void inverse(double *const _B, const double *const _A, const size_t _m, const size_t _n)
: Performs B = A^-1
void matrix_vector_product(double *const _x, const size_t _m, const double _alpha, const double *const _A, const size_t _n, const bool _transposed, const double *const _y)
: Perfroms x = alpha*OP(A)*y
void rq_destructive(double *const _R, double *const _Q, double *const _A, const size_t _m, const size_t _n)
: Performs (R,Q) = RQ(A), destroys A in the process
void solve_least_squares_destructive(double *const _x, double *const _A, const size_t _m, const size_t _n, double *const _b, const size_t _p)
: Solves min ||Ax - b||_2 for x
#define XERUS_force_inline
Collection of attributes to force gcc to inline a specific function.
Definition: standard.h:75
std::tuple< std::unique_ptr< double[]>, std::unique_ptr< double[]>, size_t > cq_destructive(double *const _A, const size_t _m, const size_t _n)
: splits A = C*Q, with _C an rxm matrix (where r is the rank of _A) and _Q orthogonal. Destroys A.
Header file for global shorthand notations of elementary integer types and attribute lists...
void solve_least_squares(double *const _x, const double *const _A, const size_t _m, const size_t _n, const double *const _b, const size_t _p)
: Solves min ||Ax - b||_2 for x