source: Sophya/trunk/SophyaExt/Blitz/blitz/tinymat.h@ 3059

Last change on this file since 3059 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

File size: 3.9 KB
RevLine 
[221]1/***************************************************************************
2 * blitz/tinymat.h Declaration of TinyMatrix<T, N, M>
3 *
4 * $Id: tinymat.h,v 1.1.1.1 1999-04-09 17:59:01 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
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-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.2 1998/03/14 00:04:47 tveldhui
27 * 0.2-alpha-05
28 *
29 * Revision 1.1 1997/07/16 14:51:20 tveldhui
30 * Update: Alpha release 0.2 (Arrays)
31 *
32 */
33
34#ifndef BZ_TINYMAT_H
35#define BZ_TINYMAT_H
36
37#ifndef BZ_BLITZ_H
38 #include <blitz/blitz.h>
39#endif
40
41#ifndef BZ_TINYVEC_H
42 #include <blitz/tinyvec.h>
43#endif
44
45#ifndef BZ_LISTINIT_H
46 #include <blitz/listinit.h>
47#endif
48
49#include <blitz/tinymatexpr.h>
50#include <blitz/meta/matassign.h>
51
52BZ_NAMESPACE(blitz)
53
54// Forward declarations
55template<class T_expr>
56class _bz_tinyMatExpr;
57
58template<class T_numtype, int N_rows, int N_columns, int N_rowStride,
59 int N_colStride>
60class _bz_tinyMatrixRef {
61
62public:
63 _bz_tinyMatrixRef(T_numtype* _bz_restrict const data)
64 : data_(data)
65 { }
66
67 T_numtype * _bz_restrict data()
68 { return (T_numtype * _bz_restrict)data_; }
69
70 T_numtype& _bz_restrict operator()(int i, int j)
71 { return data_[i * N_rowStride + j * N_colStride]; }
72
73 T_numtype operator()(int i, int j) const
74 { return data_[i * N_rowStride + j * N_colStride]; }
75
76protected:
77 T_numtype * _bz_restrict const data_;
78};
79
80template<class P_numtype, int N_rows, int N_columns>
81class TinyMatrix {
82
83public:
84 typedef P_numtype T_numtype;
85 typedef _bz_tinyMatrixRef<T_numtype, N_rows, N_columns, N_columns, 1>
86 T_reference;
87 typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix;
88
89 TinyMatrix() { }
90
91 T_numtype* _bz_restrict data()
92 { return data_; }
93
94 const T_numtype* _bz_restrict data() const
95 { return data_; }
96
97 T_numtype* _bz_restrict dataFirst()
98 { return data_; }
99
100 const T_numtype* _bz_restrict dataFirst() const
101 { return data_; }
102
103 // NEEDS_WORK -- precondition checks
104 T_numtype& _bz_restrict operator()(int i, int j)
105 { return data_[i*N_columns + j]; }
106
107 T_numtype operator()(int i, int j) const
108 { return data_[i*N_columns + j]; }
109
110 T_reference getRef()
111 { return T_reference((T_numtype*)data_); }
112
113 const T_reference getRef() const
114 { return T_reference((T_numtype*)data_); }
115
116 // Scalar operand
117 ListInitializationSwitch<T_matrix>
118 operator=(T_numtype x)
119 {
120 return ListInitializationSwitch<T_matrix>(*this, x);
121 }
122
123 template<class T_expr>
124 TinyMatrix<T_numtype, N_rows, N_columns>&
125 operator=(_bz_tinyMatExpr<T_expr> expr)
126 {
127 _bz_meta_matAssign<N_rows, N_columns, 0>::f(*this, expr,
128 _bz_update<T_numtype, _bz_typename T_expr::T_numtype>());
129 return *this;
130 }
131
132 // NEEDS_WORK -- not implemented
133 void initialize(T_numtype x)
134 { BZ_NOT_IMPLEMENTED(); }
135
136 T_numtype* _bz_restrict getInitializationIterator()
137 { return dataFirst(); }
138
139protected:
140 T_numtype data_[N_rows * N_columns];
141};
142
143BZ_NAMESPACE_END
144
145#include <blitz/meta/matvec.h> // Matrix-vector product metaprogram
146#include <blitz/meta/matmat.h> // Matrix-matrix products
147
148#endif // BZ_TINYMAT_H
149
Note: See TracBrowser for help on using the repository browser.