source: XMLIO_V2/external/include/blitz/tinymat.h @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/***************************************************************************
2 * blitz/tinymat.h       Declaration of TinyMatrix<T, N, M>
3 *
4 * $Id: tinymat.h,v 1.6 2003/12/11 03:44:22 julianc Exp $
5 *
6 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * Suggestions:          blitz-dev@oonumerics.org
19 * Bugs:                 blitz-bugs@oonumerics.org
20 *
21 * For more information, please see the Blitz++ Home Page:
22 *    http://oonumerics.org/blitz/
23 *
24 ***************************************************************************/
25
26#ifndef BZ_TINYMAT_H
27#define BZ_TINYMAT_H
28
29#ifndef BZ_BLITZ_H
30 #include <blitz/blitz.h>
31#endif
32
33#ifndef BZ_TINYVEC_H
34 #include <blitz/tinyvec.h>
35#endif
36
37#ifndef BZ_LISTINIT_H
38 #include <blitz/listinit.h>
39#endif
40
41#include <blitz/tinymatexpr.h>
42#include <blitz/meta/matassign.h>
43
44BZ_NAMESPACE(blitz)
45
46// Forward declarations
47template<typename T_expr>
48class _bz_tinyMatExpr;
49
50template<typename T_numtype, int N_rows, int N_columns, int N_rowStride,
51    int N_colStride>
52class _bz_tinyMatrixRef {
53
54public:
55    _bz_tinyMatrixRef(T_numtype* restrict const data)
56        : data_(data)
57    { }
58
59    T_numtype * restrict data()
60    { return (T_numtype * restrict)data_; }
61
62    T_numtype& restrict operator()(int i, int j)
63    { return data_[i * N_rowStride + j * N_colStride]; }
64
65    T_numtype operator()(int i, int j) const
66    { return data_[i * N_rowStride + j * N_colStride]; }
67
68protected:
69    T_numtype * restrict const data_;
70};
71
72template<typename P_numtype, int N_rows, int N_columns>
73class TinyMatrix {
74
75public:
76    typedef P_numtype T_numtype;
77    typedef _bz_tinyMatrixRef<T_numtype, N_rows, N_columns, N_columns, 1> 
78        T_reference;
79    typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix;
80
81    TinyMatrix() { }
82
83    T_numtype* restrict data()
84    { return data_; }
85
86    const T_numtype* restrict data() const
87    { return data_; }
88
89    T_numtype* restrict dataFirst()
90    { return data_; }
91
92    const T_numtype* restrict dataFirst() const
93    { return data_; }
94
95    // NEEDS_WORK -- precondition checks
96    T_numtype& restrict operator()(int i, int j)
97    { return data_[i*N_columns + j]; }
98
99    T_numtype operator()(int i, int j) const
100    { return data_[i*N_columns + j]; }
101
102    T_reference getRef()
103    { return T_reference((T_numtype*)data_); }
104
105    const T_reference getRef() const
106    { return T_reference((T_numtype*)data_); }
107
108    // Scalar operand
109    ListInitializationSwitch<T_matrix,T_numtype*>
110    operator=(T_numtype x)
111    {
112        return ListInitializationSwitch<T_matrix,T_numtype*>(*this, x);
113    }
114
115    template<typename T_expr>
116    TinyMatrix<T_numtype, N_rows, N_columns>&
117    operator=(_bz_tinyMatExpr<T_expr> expr)
118    {
119        _bz_meta_matAssign<N_rows, N_columns, 0>::f(*this, expr,
120            _bz_update<T_numtype, _bz_typename T_expr::T_numtype>());
121        return *this;
122    }
123
124    void initialize(T_numtype x)
125    { 
126        for (int i=0; i < N_rows; ++i)
127          for (int j=0; j < N_columns; ++j)
128            (*this)(i,j) = x;
129    }
130
131    T_numtype* restrict getInitializationIterator()
132    { return dataFirst(); }
133
134protected:
135    T_numtype data_[N_rows * N_columns];
136};
137
138BZ_NAMESPACE_END
139
140#include <blitz/meta/matvec.h>     // Matrix-vector product metaprogram
141#include <blitz/meta/matmat.h>     // Matrix-matrix products
142#include <blitz/tinymatio.cc>      // I/O operations
143
144#endif // BZ_TINYMAT_H
145
Note: See TracBrowser for help on using the repository browser.