GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
array
MSparse-defs.h
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 2004-2013 David Bateman
4
Copyright (C) 1998-2004 Andy Adler
5
6
This file is part of Octave.
7
8
Octave is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 3 of the License, or (at your
11
option) any later version.
12
13
Octave is distributed in the hope that it will be useful, but WITHOUT
14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16
for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Octave; see the file COPYING. If not, see
20
<http://www.gnu.org/licenses/>.
21
22
*/
23
24
#if !defined (octave_MSparse_defs_h)
25
#define octave_MSparse_defs_h 1
26
27
// Nothing like a little CPP abuse to brighten everyone's day.
28
29
// A macro that can be used to declare and instantiate OP= operators.
30
#define SPARSE_OP_ASSIGN_DECL(A_T, E_T, OP, PFX, API, LTGT, RHS_T) \
31
PFX API A_T<E_T>& \
32
operator OP LTGT (A_T<E_T>&, const RHS_T&)
33
34
// All the OP= operators that we care about.
35
#define SPARSE_OP_ASSIGN_DECLS(A_T, E_T, PFX, API, LTGT, RHS_T) \
36
SPARSE_OP_ASSIGN_DECL (A_T, E_T, +=, PFX, API, LTGT, RHS_T); \
37
SPARSE_OP_ASSIGN_DECL (A_T, E_T, -=, PFX, API, LTGT, RHS_T);
38
39
// Generate forward declarations for OP= operators.
40
#define SPARSE_OP_ASSIGN_FWD_DECLS(A_T, RHS_T, API) \
41
SPARSE_OP_ASSIGN_DECLS (A_T, T, template <typename T>, API, , RHS_T)
42
43
// Generate friend declarations for the OP= operators.
44
#define SPARSE_OP_ASSIGN_FRIENDS(A_T, RHS_T, API) \
45
SPARSE_OP_ASSIGN_DECLS (A_T, T, friend, API, <>, RHS_T)
46
47
// Instantiate the OP= operators.
48
#define SPARSE_OP_ASSIGN_DEFS(A_T, E_T, RHS_T, API) \
49
SPARSE_OP_ASSIGN_DECLS (A_T, E_T, template, API, , RHS_T)
50
51
// A function that can be used to forward OP= operations from derived
52
// classes back to us.
53
#define SPARSE_OP_ASSIGN_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
54
inline R \
55
F (X_T& x, const Y_T& y) \
56
{ \
57
return R (F (C_X (x), C_Y (y))); \
58
}
59
60
// All the OP= operators that we care about forwarding.
61
#define SPARSE_OP_ASSIGN_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
62
SPARSE_OP_ASSIGN_FWD_FCN (R, operator +=, T, C_X, X_T, C_Y, Y_T) \
63
SPARSE_OP_ASSIGN_FWD_FCN (R, operator -=, T, C_X, X_T, C_Y, Y_T)
64
65
// A macro that can be used to declare and instantiate unary operators.
66
#define SPARSE_UNOP(A_T, E_T, F, PFX, API, LTGT) \
67
PFX API A_T<E_T> \
68
F LTGT (const A_T<E_T>&)
69
70
// All the unary operators that we care about.
71
#define SPARSE_UNOP_DECLS(A_T, E_T, PFX, API, LTGT) \
72
SPARSE_UNOP (A_T, E_T, operator +, PFX, API, LTGT); \
73
SPARSE_UNOP (A_T, E_T, operator -, PFX, API, LTGT);
74
75
// Generate forward declarations for unary operators.
76
#define SPARSE_UNOP_FWD_DECLS(A_T, API) \
77
SPARSE_UNOP_DECLS (A_T, T, template <typename T>, API, )
78
79
// Generate friend declarations for the unary operators.
80
#define SPARSE_UNOP_FRIENDS(A_T, API) \
81
SPARSE_UNOP_DECLS (A_T, T, friend, API, <>)
82
83
// Instantiate the unary operators.
84
#define SPARSE_UNOP_DEFS(A_T, E_T, API) \
85
SPARSE_UNOP_DECLS (A_T, E_T, template, API, )
86
87
// A function that can be used to forward unary operations from derived
88
// classes back to us.
89
#define SPARSE_UNOP_FWD_FCN(R, F, T, C_X, X_T) \
90
inline R \
91
F (const X_T& x) \
92
{ \
93
return R (F (C_X (x))); \
94
}
95
96
// All the unary operators that we care about forwarding.
97
#define SPARSE_UNOP_FWD_DEFS(R, T, C_X, X_T) \
98
SPARSE_UNOP_FWD_FCN (R, operator +, T, C_X, X_T) \
99
SPARSE_UNOP_FWD_FCN (R, operator -, T, C_X, X_T)
100
101
// A macro that can be used to declare and instantiate binary operators.
102
#define SPARSE_BINOP_DECL(A_T, E_T, F, PFX, API, LTGT, X_T, Y_T) \
103
PFX API A_T<E_T> \
104
F LTGT (const X_T&, const Y_T&)
105
106
// All the binary operators that we care about. We have two
107
// sets of macros since the MArray OP MArray operations use functions
108
// (product and quotient) instead of operators (*, /).
109
#define SPARSE_BINOP_DECLS(A_T, F_T, E_T, PFX, API, LTGT, X_T, Y_T) \
110
SPARSE_BINOP_DECL (F_T, E_T, operator +, PFX, API, LTGT, X_T, Y_T); \
111
SPARSE_BINOP_DECL (F_T, E_T, operator -, PFX, API, LTGT, X_T, Y_T); \
112
SPARSE_BINOP_DECL (A_T, E_T, operator *, PFX, API, LTGT, X_T, Y_T); \
113
SPARSE_BINOP_DECL (A_T, E_T, operator /, PFX, API, LTGT, X_T, Y_T);
114
115
#define SPARSE_AA_BINOP_DECLS(A_T, E_T, PFX, API, LTGT) \
116
SPARSE_BINOP_DECL (A_T, E_T, operator +, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
117
SPARSE_BINOP_DECL (A_T, E_T, operator -, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
118
SPARSE_BINOP_DECL (A_T, E_T, quotient, PFX, API, LTGT, A_T<E_T>, A_T<E_T>); \
119
SPARSE_BINOP_DECL (A_T, E_T, product, PFX, API, LTGT, A_T<E_T>, A_T<E_T>);
120
121
// Generate forward declarations for binary operators.
122
#define SPARSE_BINOP_FWD_DECLS(A_T, F_T, API) \
123
SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , A_T<T>, T) \
124
SPARSE_BINOP_DECLS (A_T, F_T, T, template <typename T>, API, , T, A_T<T>) \
125
SPARSE_AA_BINOP_DECLS (A_T, T, template <typename T>, API, )
126
127
// Generate friend declarations for the binary operators.
128
#define SPARSE_BINOP_FRIENDS(A_T, F_T, API) \
129
SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, A_T<T>, T) \
130
SPARSE_BINOP_DECLS (A_T, F_T, T, friend, API, <>, T, A_T<T>) \
131
SPARSE_AA_BINOP_DECLS (A_T, T, friend, API, <>)
132
133
// Instantiate the binary operators.
134
#define SPARSE_BINOP_DEFS(A_T, F_T, E_T, API) \
135
SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , A_T<E_T>, E_T) \
136
SPARSE_BINOP_DECLS (A_T, F_T, E_T, template, API, , E_T, A_T<E_T>) \
137
SPARSE_AA_BINOP_DECLS (A_T, E_T, template, API, )
138
139
// A function that can be used to forward binary operations from derived
140
// classes back to us.
141
#define SPARSE_BINOP_FWD_FCN(R, F, T, C_X, X_T, C_Y, Y_T) \
142
inline R \
143
F (const X_T& x, const Y_T& y) \
144
{ \
145
return R (F (C_X (x), C_Y (y))); \
146
}
147
148
// The binary operators that we care about forwarding. We have two
149
// sets of macros since the MSparse OP MSparse operations use functions
150
// (product and quotient) instead of operators (*, /).
151
#define SPARSE_BINOP_FWD_DEFS(R, F, T, C_X, X_T, C_Y, Y_T) \
152
SPARSE_BINOP_FWD_FCN (F, operator +, T, C_X, X_T, C_Y, Y_T) \
153
SPARSE_BINOP_FWD_FCN (F, operator -, T, C_X, X_T, C_Y, Y_T) \
154
SPARSE_BINOP_FWD_FCN (R, operator *, T, C_X, X_T, C_Y, Y_T) \
155
SPARSE_BINOP_FWD_FCN (R, operator /, T, C_X, X_T, C_Y, Y_T)
156
157
#define SPARSE_AA_BINOP_FWD_DEFS(R, T, C_X, X_T, C_Y, Y_T) \
158
SPARSE_BINOP_FWD_FCN (R, operator +, T, C_X, X_T, C_Y, Y_T) \
159
SPARSE_BINOP_FWD_FCN (R, operator -, T, C_X, X_T, C_Y, Y_T) \
160
SPARSE_BINOP_FWD_FCN (R, product, T, C_X, X_T, C_Y, Y_T) \
161
SPARSE_BINOP_FWD_FCN (R, quotient, T, C_X, X_T, C_Y, Y_T)
162
163
// Forward declarations for the MSparse operators.
164
#define SPARSE_OPS_FORWARD_DECLS(A_T, F_T, API) \
165
template <class T> \
166
class A_T; \
167
\
168
/* SPARSE_OP_ASSIGN_FWD_DECLS (A_T, T) */
\
169
SPARSE_OP_ASSIGN_FWD_DECLS (A_T, A_T<T>, API) \
170
SPARSE_UNOP_FWD_DECLS (A_T, API) \
171
SPARSE_BINOP_FWD_DECLS (A_T, F_T, API)
172
173
// Friend declarations for the MSparse operators.
174
#define SPARSE_OPS_FRIEND_DECLS(A_T, F_T, API) \
175
/* SPARSE_OP_ASSIGN_FRIENDS (A_T, T) */
\
176
SPARSE_OP_ASSIGN_FRIENDS (A_T, A_T<T>, API) \
177
SPARSE_UNOP_FRIENDS (A_T, API) \
178
SPARSE_BINOP_FRIENDS (A_T, F_T, API)
179
180
// The following macros are for external use.
181
182
// Instantiate all the MSparse friends for MSparse element type T.
183
#define INSTANTIATE_SPARSE_FRIENDS(T, API) \
184
/* SPARSE_OP_ASSIGN_DEFS (MSparse, T, T) */
\
185
SPARSE_OP_ASSIGN_DEFS (MSparse, T, MSparse<T>, API) \
186
SPARSE_UNOP_DEFS (MSparse, T, API) \
187
SPARSE_BINOP_DEFS (MSparse, MArray, T, API)
188
189
// Define all the MSparse forwarding functions for return type R and
190
// MSparse element type T
191
#define SPARSE_FORWARD_DEFS(B, R, F, T) \
192
/* SPARSE_OP_ASSIGN_FWD_DEFS */
\
193
/* (R, T, dynamic_cast<B<T>&>, R, , T) */
\
194
\
195
SPARSE_OP_ASSIGN_FWD_DEFS \
196
(R, T, \
197
dynamic_cast<B<T>&>, R, dynamic_cast<const B<T>&>, R) \
198
\
199
SPARSE_UNOP_FWD_DEFS \
200
(R, T, dynamic_cast<const B<T>&>, R) \
201
\
202
SPARSE_BINOP_FWD_DEFS \
203
(R, F, T, dynamic_cast<const B<T>&>, R, , T) \
204
\
205
SPARSE_BINOP_FWD_DEFS \
206
(R, F, T, , T, dynamic_cast<const B<T>&>, R) \
207
\
208
SPARSE_AA_BINOP_FWD_DEFS \
209
(R, T, dynamic_cast<const B<T>&>, R, dynamic_cast<const B<T>&>, R)
210
211
// Now we have all the definitions we need.
212
213
#endif
Generated on Mon Dec 30 2013 03:04:44 for GNU Octave by
1.8.1.2