banded.h

来自「高效的c++科学算法库」· C头文件 代码 · 共 127 行

H
127
字号
#ifndef SL_MATRIX_STRUCTURES_BANDED_BANDED_H#define SL_MATRIX_STRUCTURES_BANDED_BANDED_H/* ****************************** * Scientific Library (GNU Public Licence) * * Author: Laurent Deniau, Laurent.Deniau@cern.ch * * $Id: banded.h,v 1.1 1998/11/05 12:48:36 paubert Exp $ * * Suggestions: sl@mathinsa.insa-lyon.fr * Bugs:   sl-bugs@mathinsa.insa-lyon.fr * * For more information, please see the sl++ Home Page: * http://wwwinfo.cern.ch/~ldeniau/sl.html * ****************************** */#ifndef SL_MATRIX_STRUCTURES_BANDED_H#error <sl/matrix/structures/banded/banded.h> must be included via <sl/matrix/structures/banded.h>#endif#ifdef HAVE_NAMESPACEnamespace sl {#endif// Banded matrix structure//// LB=1, UB=2// [1 2 3 .]// [4 5 6 7]// [. 8 9 0]// [. . 1 2]//// Default template is equivalent to Diagonal matrix    template <Index LB, Index UB>        class BandedIterator;        template <Index LB, Index UB>        class Banded : public MatrixStructure {                                    public:                        typedef BandedIterator<LB,UB> iterator_t;                        Index lbands () const { return LB; }            Index ubands () const { return UB; }            Index nbands () const { return LB+UB+1; }                        size_t size () const { return (my_n<=my_p+LB ? my_n : my_p+LB)*nbands(); }            Index  rows () const { return my_n; }            Index  cols () const { return my_p; }            Index firstInRow (Index const i) const { return i<=LB ? MinIndex : i-LB; }            Index firstInCol (Index const j) const { return j<=UB ? MinIndex : j-UB; }            Index lastInRow  (Index const i) const { return i+UB>=my_p ? my_p : i+UB; }            Index lastInCol  (Index const j) const { return j+LB>=my_n ? my_n : j+LB; }            static Bool isRowMajor () { return true; }              // map(MinIndex,MinIndex)            ptrdiff_t offset () const { return (UB+1)*MinIndex; }            Banded () : my_n (0), my_p (0) { }            Banded (Index const n) : my_n (n), my_p (n)            {                assert( n>LB );                assert( n>UB );            }            Banded (Index const n, Index const p) : my_n (n), my_p (p)            {                assert( n==p );                assert( n>LB );                assert( n>UB );            }              // WARNING: Do NOT declare the copy constructor !              void            resize (Index const n, Index const p) {                my_n = n; my_p = p;            }            template <typename T_value>            T_value&            get (T_value* const data, Index const i, Index const j) {                return i<=LB+j && j<=UB+i ? data[map(i,j)] : zero_ref<T_value>();            }            template <typename T_value>            T_value            get (T_value const* const data, Index const i, Index const j) const {                return i<=LB+j && j<=UB+i ? data[map(i,j)] : T_value();            }            private:            Index            map (Index const i, Index const j) const {                return i*nbands()+j-i;            }            Index my_n, my_p;        };#ifdef HAVE_NAMESPACE}#endif #endif // SL_MATRIX_STRUCTURES_BANDED_BANDED_H

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?