/usr/include/rheolef/ssk.h is in librheolef-dev 5.93-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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | # ifndef _SKIT_SSK_H
# define _SKIT_SSK_H
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///
/// =========================================================================
/*Class:ssk
NAME: @code{ssk} - symmetric skyline matrix format
@clindex ssk
@clindex csr
@clindex vec
@clindex permutation
@toindex spooles, multifrontal solver library
@toindex umfpack, multifrontal solver library
@toindex taucs, out-of-core sparse solver library
@cindex Choleski factorization
@cindex direct solver
@cindex multifrontal factorization
@cindex skyline data structure
@cindex chevron data structure
@cindex Gibbs renumbering
DESCRIPTION:
@noindent
The class implements a symmetric matrix Choleski factorization.
Let @var{a} be a square invertible matrix in
@code{csr} format (@pxref{csr class}).
@example
csr<Float> a;
@end example
@noindent
We get the factorization by:
@example
ssk<Float> m = ldlt(a);
@end example
@noindent
Each call to the direct solver for a*x = b writes either:
@example
vec<Float> x = m.solve(b);
@end example
@noindent
or
@example
m.solve(b,x);
@end example
DATA STRUCTURE:
@noindent
The storage is either skyline, multi-file or
chevron.
This alternative depends upon the configuration
(@pxref{Installing}).
The chevron data structure is related to the multifrontal
algorithm and is implemented by using the spooles library.
The multi-file data structure refers to the out-of-core
algorithm and is implemented by using the taucs library.
If such a library is not available, the @code{ssk} class
implements a skyline storage scheme and the profil storage of the
@code{ssk} matrix is optimized by optimizing the renumbering,
by using the Gibbs, Pooles and Stockmeyer algorithm available
via the @code{permutation} class
(@pxref{permutation class}).
@quotation
Algorithm 582, collected Algorithms from ACM.
Algorithm appeared in ACM-Trans. Math. Software, vol.8, no. 2,
Jun., 1982, p. 190.
@end quotation
@noindent
When implementing the skyline data structure,
we can go back to the @code{csr} format, for the
pupose of pretty-printing:
@example
cout << ps << color << logscale << csr<Float>(m);
@end example
AUTHOR:
Pierre Saramito
| Pierre.Saramito@imag.fr
LMC-IMAG, 38041 Grenoble cedex 9, France
DATE: 21 january 1997
METHODS: @ssk
End:
*/
# include "rheolef/array.h"
# include "rheolef/csr.h"
# include "rheolef/permutation.h"
namespace rheolef {
#if defined(_RHEOLEF_HAVE_SPOOLES)
template<class T>
class spooles_rep : public occurence {
void *_p;
public:
typedef unsigned int size_type;
typedef T element_type;
spooles_rep ();
spooles_rep (const csr<element_type>&);
~spooles_rep();
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
void solve(const vec<element_type>& b, vec<element_type>& x) const;
void factorize_ldlt();
};
//<ssk:
template<class T>
class ssk : smart_pointer<spooles_rep<T> > {
public:
// typedefs:
typedef T element_type;
typedef typename spooles_rep<T>::size_type size_type;
// allocators/deallocators:
ssk ();
explicit ssk<T> (const csr<T>&);
// accessors:
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
// factorisation and solver:
void solve(const vec<T>& b, vec<T>& x) const;
vec<T> solve(const vec<T>& b) const;
void factorize_ldlt();
protected:
const spooles_rep<T>& data() const {
return smart_pointer<spooles_rep<T> >::data();
}
spooles_rep<T>& data() {
return smart_pointer<spooles_rep<T> >::data();
}
};
template <class T>
ssk<T> ldlt (const csr<T>& m);
//>ssk:
// ===============================[ INLINED ]====================================
template <class T>
inline
ssk<T>::ssk ()
: smart_pointer<spooles_rep<T> > (new_macro(spooles_rep<T>))
{
}
template <class T>
inline
ssk<T>::ssk (const csr<T>& a)
: smart_pointer<spooles_rep<T> > (new_macro(spooles_rep<T> (a)))
{
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nrow () const
{
return data().nrow();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::ncol () const
{
return data().ncol();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nnz () const
{
return data().nnz();
}
template <class T>
inline
void
ssk<T>::solve(const vec<T>& b, vec<T>& x) const
{
data().solve(b,x);
}
template <class T>
inline
void
ssk<T>::factorize_ldlt ()
{
data().factorize_ldlt();
}
// ! _RHEOLEF_HAVE_SPOOLES
#elif defined(_RHEOLEF_HAVE_TAUCS)
template<class T>
class taucs_rep : public occurence {
public:
typedef unsigned int size_type;
typedef T element_type;
taucs_rep ();
taucs_rep (const csr<element_type>&);
taucs_rep (const taucs_rep<T>&);
~taucs_rep();
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
void solve(const vec<element_type>& b, vec<element_type>& x) const;
void factorize_ldlt();
// data:
protected:
void *_p;
private:
};
template<class T>
class ssk : smart_pointer<taucs_rep<T> > {
public:
// typedefs:
typedef taucs_rep<T>::size_type size_type;
typedef T element_type;
// allocators/deallocators:
ssk ();
explicit ssk<T> (const csr<T>&);
// accessors:
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
// factorisation and solver:
void solve(const vec<T>& b, vec<T>& x) const;
vec<T> solve(const vec<T>& b) const;
void factorize_ldlt();
protected:
const taucs_rep<T>& data() const {
return smart_pointer<taucs_rep<T> >::data();
}
};
template <class T>
ssk<T> ldlt (const csr<T>& m);
// ===============================[ INLINED ]====================================
template <class T>
inline
ssk<T>::ssk ()
: smart_pointer<taucs_rep<T> > (new_macro(taucs_rep<T>))
{
}
template <class T>
inline
ssk<T>::ssk (const csr<T>& a)
: smart_pointer<taucs_rep<T> > (new_macro(taucs_rep<T> (a)))
{
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nrow () const
{
return data().nrow();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::ncol () const
{
return data().ncol();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nnz () const
{
return data().nnz();
}
template <class T>
inline
void
ssk<T>::solve(const vec<T>& b, vec<T>& x) const
{
data().solve(b,x);
}
template <class T>
inline
void
ssk<T>::factorize_ldlt ()
{
data().factorize_ldlt();
}
// ! _RHEOLEF_HAVE_TAUCS
#elif defined(_RHEOLEF_HAVE_UMFPACK)
template<class T>
class umfpack_rep {
void *_p;
public:
typedef unsigned int size_type;
typedef T element_type;
umfpack_rep ();
umfpack_rep (const csr<element_type>&);
~umfpack_rep();
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
void solve(const vec<element_type>& b, vec<element_type>& x) const;
void factorize();
};
//<ssk:
template<class T>
class ssk : smart_pointer<umfpack_rep<T> > {
public:
// typedefs:
typedef T element_type;
typedef typename umfpack_rep<T>::size_type size_type;
// allocators/deallocators:
ssk ();
explicit ssk<T> (const csr<T>&);
// accessors:
size_type nrow () const;
size_type ncol () const;
size_type nnz () const;
// factorisation and solver:
void solve(const vec<T>& b, vec<T>& x) const;
vec<T> solve(const vec<T>& b) const;
void factorize_ldlt();
void factorize_lu();
protected:
const umfpack_rep<T>& data() const {
return smart_pointer<umfpack_rep<T> >::data();
}
umfpack_rep<T>& data() {
return smart_pointer<umfpack_rep<T> >::data();
}
};
template <class T>
ssk<T> ldlt (const csr<T>& m);
//>ssk:
// ===============================[ INLINED ]====================================
template <class T>
inline
ssk<T>::ssk ()
: smart_pointer<umfpack_rep<T> > (new_macro(umfpack_rep<T>))
{
}
template <class T>
inline
ssk<T>::ssk (const csr<T>& a)
: smart_pointer<umfpack_rep<T> > (new_macro(umfpack_rep<T> (a)))
{
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nrow () const
{
return data().nrow();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::ncol () const
{
return data().ncol();
}
template <class T>
inline
typename ssk<T>::size_type
ssk<T>::nnz () const
{
return data().nnz();
}
template <class T>
inline
void
ssk<T>::solve(const vec<T>& b, vec<T>& x) const
{
data().solve(b,x);
}
template <class T>
inline
void
ssk<T>::factorize_ldlt ()
{
data().factorize();
}
template <class T>
inline
void
ssk<T>::factorize_lu ()
{
data().factorize();
}
template <class T>
inline
ssk<T>
lu (const csr<T>& m)
{
ssk<T> a(m);
a.factorize_lu();
return a;
}
// ! _RHEOLEF_HAVE_UMFPACK
#else // ! UMF TAUCS SPOOLES...
template<class T>
class ssk {
public:
// allocators/deallocators:
ssk ();
explicit ssk (const csr<T>&);
// factorisation LDTt and solver:
void solve(const vec<T>& b, vec<T>& x) const;
vec<T> solve(const vec<T>& b) const;
void factorize_ldlt ();
// accessors:
unsigned int nrow () const { return _ISKY.size()-1; }
unsigned int ncol () const { return nrow(); }
unsigned int nnz () const { return _ASKY.size(); }
typedef typename Array<unsigned int>::const_iterator const_iterator_isky;
typedef typename Array<T>::const_iterator const_iterator_asky;
const_iterator_isky begin_isky () const { return _ISKY.begin(); }
const_iterator_isky end_isky () const { return _ISKY.end(); }
const_iterator_asky begin_asky () const { return _ASKY.begin(); }
const_iterator_asky end_asky () const { return _ASKY.end(); }
// output:
std::ostream& dump(std::ostream&) const;
// internal accessors:
private:
// index in ASKY of the A(i,j) element, colmin(i) <= j <= i
unsigned int index_a(unsigned int i, unsigned int j) const
{ return _ISKY (i+1) - i + j - 1; }
// value of the A(i,j) element, colmin(i) <= j <= i
const T& operator () (unsigned int i, unsigned int j) const
{ return _ASKY (index_a(i,j)); }
T& operator () (unsigned int i, unsigned int j)
{ return _ASKY (index_a(i,j)); }
// index in ASKY of the first element of the i-th row
unsigned int index_colmin(unsigned int i) const
{ return _ISKY (i); }
// column index j of the element asky(q) in the i-th row
unsigned int col(unsigned int i, unsigned int q) const
{ return q - _ISKY (i+1) + i + 1; }
// column index j of the first element of the i-th row
unsigned int colmin(unsigned int i) const
{ return col(i, index_colmin(i)); }
// index in ASKY of the i-th diagonal element
unsigned int index_diag(unsigned int i) const
{ return _ISKY (i+1) - 1; }
// data:
private:
Array<T> _ASKY ;
Array<unsigned int> _ISKY;
permutation _p;
};
template<class T>
ssk<T>
ldlt (const csr<T>& m);
#endif // ! _RHEOLEF_HAVE_SPOOLES && !_RHEOLEF_HAVE_TAUCS
template <class T>
inline
vec<T>
ssk<T>::solve (const vec<T>& b) const
{
vec<T> x(b.n());
solve(b,x);
return x;
}
template <class T>
inline
ssk<T>
ldlt (const csr<T>& m)
{
ssk<T> a(m);
a.factorize_ldlt();
return a;
}
}// namespace rheolef
#endif /* _SKIT_SSK_H */
|