This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinymat.h
155 lines (122 loc) · 4.2 KB
/
tinymat.h
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
/***************************************************************************
* blitz/tinymat.h Declaration of TinyMatrix<T, N, M>
*
* $Id: tinymat.h,v 1.6 2003/12/11 03:44:22 julianc Exp $
*
* Copyright (C) 1997-2001 Todd Veldhuizen <[email protected]>
*
* This program 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.
*
* This program 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.
*
* Suggestions: [email protected]
* Bugs: [email protected]
*
* For more information, please see the Blitz++ Home Page:
* http://oonumerics.org/blitz/
*
***************************************************************************/
/***************************************************************************
* Changes made, in accordance with the Artistic License, by Cory Beutler
*
* - Removed the restrict keyword on some return types
* Returning a pointer returns an r-value pointer. GCC ignores these
* anyway as the r-value is already optimized.
*
* - Removed trailing whitespace
*
***************************************************************************/
#ifndef BZ_TINYMAT_H
#define BZ_TINYMAT_H
#ifndef BZ_BLITZ_H
#include <blitz/blitz.h>
#endif
#ifndef BZ_TINYVEC_H
#include <blitz/tinyvec.h>
#endif
#ifndef BZ_LISTINIT_H
#include <blitz/listinit.h>
#endif
#include <blitz/tinymatexpr.h>
#include <blitz/meta/matassign.h>
BZ_NAMESPACE(blitz)
// Forward declarations
template<typename T_expr>
class _bz_tinyMatExpr;
template<typename T_numtype, int N_rows, int N_columns, int N_rowStride,
int N_colStride>
class _bz_tinyMatrixRef {
public:
_bz_tinyMatrixRef(T_numtype* restrict const data)
: data_(data)
{ }
T_numtype * data()
{ return (T_numtype * restrict)data_; }
T_numtype& restrict operator()(int i, int j)
{ return data_[i * N_rowStride + j * N_colStride]; }
T_numtype operator()(int i, int j) const
{ return data_[i * N_rowStride + j * N_colStride]; }
protected:
T_numtype * restrict const data_;
};
template<typename P_numtype, int N_rows, int N_columns>
class TinyMatrix {
public:
typedef P_numtype T_numtype;
typedef _bz_tinyMatrixRef<T_numtype, N_rows, N_columns, N_columns, 1>
T_reference;
typedef TinyMatrix<T_numtype, N_rows, N_columns> T_matrix;
TinyMatrix() { }
T_numtype* data()
{ return data_; }
const T_numtype* data() const
{ return data_; }
T_numtype* dataFirst()
{ return data_; }
const T_numtype* dataFirst() const
{ return data_; }
// NEEDS_WORK -- precondition checks
T_numtype& restrict operator()(int i, int j)
{ return data_[i*N_columns + j]; }
T_numtype operator()(int i, int j) const
{ return data_[i*N_columns + j]; }
T_reference getRef()
{ return T_reference((T_numtype*)data_); }
const T_reference getRef() const
{ return T_reference((T_numtype*)data_); }
// Scalar operand
ListInitializationSwitch<T_matrix,T_numtype*>
operator=(T_numtype x)
{
return ListInitializationSwitch<T_matrix,T_numtype*>(*this, x);
}
template<typename T_expr>
TinyMatrix<T_numtype, N_rows, N_columns>&
operator=(_bz_tinyMatExpr<T_expr> expr)
{
_bz_meta_matAssign<N_rows, N_columns, 0>::f(*this, expr,
_bz_update<T_numtype, _bz_typename T_expr::T_numtype>());
return *this;
}
void initialize(T_numtype x)
{
for (int i=0; i < N_rows; ++i)
for (int j=0; j < N_columns; ++j)
(*this)(i,j) = x;
}
T_numtype* getInitializationIterator()
{ return dataFirst(); }
protected:
T_numtype data_[N_rows * N_columns];
};
BZ_NAMESPACE_END
#include <blitz/meta/matvec.h> // Matrix-vector product metaprogram
#include <blitz/meta/matmat.h> // Matrix-matrix products
#include <blitz/tinymatio.cc> // I/O operations
#endif // BZ_TINYMAT_H