/usr/include/vmmlib/lapack_gaussian_elimination.hpp is in libvmmlib-dev 1.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | #ifndef __VMML__VMMLIB_LAPACK_GAUSSIAN_ELIMINATION__HPP__
#define __VMML__VMMLIB_LAPACK_GAUSSIAN_ELIMINATION__HPP__
#include <vmmlib/matrix.hpp>
#include <vmmlib/vector.hpp>
#include <vmmlib/exception.hpp>
#include <vmmlib/lapack_types.hpp>
#include <vmmlib/lapack_includes.hpp>
#include <string>
/**
*
* this is a wrapper for the following lapack routines:
*
* xGESV
*
*
*/
namespace vmml
{
// XYYZZZ
// X = data type: S - float, D - double
// YY = matrix type, GE - general, TR - triangular
// ZZZ = function name
namespace lapack
{
//
//
//
// SGESV/DGESV
//
//
template< typename float_t >
struct xgesv_params
{
lapack_int n; // order of matrix A = M * N
lapack_int nrhs; // number of columns of B
float_t* a; // input A, output P*L*U
lapack_int lda; // leading dimension of A (for us: number of rows)
lapack_int* ipiv; // pivot indices, integer array of size N
float_t* b; // input b, output X
lapack_int ldb; // leading dimension of b
lapack_int info;
friend std::ostream& operator << ( std::ostream& os,
const xgesv_params< float_t >& p )
{
os
<< "n " << p.n
<< " nrhs " << p.nrhs
<< " lda " << p.lda
<< " ldb " << p.ldb
<< " info " << p.info
<< std::endl;
return os;
}
};
#if 0
/* Subroutine */ int dgesv_(integer *n, integer *nrhs, doublereal *a, integer
*lda, integer *ipiv, doublereal *b, integer *ldb, integer *info);
#endif
template< typename float_t >
inline void
xgesv_call( xgesv_params< float_t >& p )
{
VMMLIB_ERROR( "not implemented for this type.", VMMLIB_HERE );
}
template<>
inline void
xgesv_call( xgesv_params< float >& p )
{
sgesv_(
&p.n,
&p.nrhs,
p.a,
&p.lda,
p.ipiv,
p.b,
&p.ldb,
&p.info
);
}
template<>
inline void
xgesv_call( xgesv_params< double >& p )
{
dgesv_(
&p.n,
&p.nrhs,
p.a,
&p.lda,
p.ipiv,
p.b,
&p.ldb,
&p.info
);
}
template< size_t M, size_t N, typename float_t >
struct gaussian_elimination
{
// computes x ( Ax = b ). x replaces b on output.
void compute(
matrix< N, N, float_t >& A,
matrix< N, M, float_t >& b
);
void compute(
matrix< N, N, float_t >& A,
vector< N, float_t >& b
);
gaussian_elimination();
~gaussian_elimination();
const lapack::xgesv_params< float_t >& get_params() { return p; }
lapack::xgesv_params< float_t > p;
}; // struct lapack_linear_least_squares
template< size_t M, size_t N, typename float_t >
void
gaussian_elimination< M, N, float_t >::
compute(
matrix< N, N, float_t >& A,
matrix< N, M, float_t >& b
)
{
p.a = A.array;
p.b = b.array;
lapack::xgesv_call( p );
if ( p.info != 0 )
{
if ( p.info < 0 )
VMMLIB_ERROR( "invalid value in input matrix", VMMLIB_HERE );
else
VMMLIB_ERROR( "factor U is exactly singular, solution could not be computed.", VMMLIB_HERE );
}
}
template< size_t M, size_t N, typename float_t >
void
gaussian_elimination< M, N, float_t >::
compute(
matrix< N, N, float_t >& A,
vector< N, float_t >& b
)
{
p.a = A.array;
p.b = b.array;
lapack::xgesv_call( p );
if ( p.info != 0 )
{
if ( p.info < 0 )
VMMLIB_ERROR( "invalid value in input matrix", VMMLIB_HERE );
else
VMMLIB_ERROR( "factor U is exactly singular, solution could not be computed.", VMMLIB_HERE );
}
}
template< size_t M, size_t N, typename float_t >
gaussian_elimination< M, N, float_t >::
gaussian_elimination()
{
p.n = N;
p.nrhs = M;
p.lda = N;
p.ldb = N;
p.ipiv = new lapack_int[ N ];
}
template< size_t M, size_t N, typename float_t >
gaussian_elimination< M, N, float_t >::
~gaussian_elimination()
{
delete[] p.ipiv;
}
} // namespace lapack
} // namespace vmml
#endif
|