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
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
259
  
260
  
261
  
262
  
263
  
264
  
265
  
266
  
267
  
268
  
269
  
270
  
271
  
272
  
273
  
274
  
275
  
276
  
277
  
278
  
279
  
280
  
281
  
282
  
283
  
284
  
285
  
286
  
287
  
288
  
289
  
290
  
291
  
292
  
293
  
294
  
295
  
296
  
297
  
298
  
299
  
300
  
301
  
302
  
303
  
304
  
305
  
/* 
|| This file is part of Pike. For copyright information see COPYRIGHT. 
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING 
|| for more information. 
*/ 
 
#include "global.h" 
#include "config.h" 
 
#include <math.h> 
 
#include "pike_error.h" 
#include "interpret.h" 
#include "svalue.h" 
#include "operators.h" 
#include "builtin_functions.h" 
#include "module_support.h" 
#include "pike_types.h" 
 
#include "math_module.h" 
 
#include "bignum.h" 
 
#ifdef HAVE_MPI_H 
#include <mpi.h> 
#endif 
 
/*! @module Math 
 */ 
 
/*! @class Matrix 
 *! Matrix representation with double precision floating point values. 
 */ 
 
static struct pike_string *s__clr; 
static struct pike_string *s_identity; 
static struct pike_string *s_rotate; 
 
extern struct program *math_matrix_program; 
extern struct program *math_smatrix_program; 
extern struct program *math_imatrix_program; 
extern struct program *math_fmatrix_program; 
extern struct program *math_lmatrix_program; 
 
#ifdef HAS_MPI 
struct size_info { 
    int x, y; 
}; 
 
struct op_info { 
    struct object *o; 
    void **data; 
}; 
 
extern PMOD_EXPORT struct object *mpi_ex_op(struct op_info (*create)(void *), 
                                            struct svalue *ufun, int commute, 
                                            void *info, int shift, int len); 
 
#endif 
 
#define PNAME "Matrix" 
#define FTYPE double 
#define PTYPE tFloat 
#define matrixX(X) PIKE_CONCAT(matrix,X) 
#define Xmatrix(X) PIKE_CONCAT(X,matrix) 
#define XmatrixY(X,Y) PIKE_CONCAT3(X,matrix,Y) 
#define PUSH_ELEM( X )  push_float( (FLOAT_TYPE)(X) ) 
#define MATRIX_MPI_TYPE MPI_DOUBLE 
#define MATRIX_MPI_SHIFT (17<<3) 
#include <matrix_code.h> 
#undef MATRIX_MPI_SHIFT 
#undef MATRIX_MPI_TYPE 
#undef PUSH_ELEM 
#undef matrixX 
#undef Xmatrix 
#undef XmatrixY 
#undef FTYPE 
#undef PTYPE 
#undef PNAME 
 
#define PNAME "IMatrix" 
#define FTYPE int 
#define PTYPE tInt 
#define matrixX(X) PIKE_CONCAT(imatrix,X) 
#define Xmatrix(X) PIKE_CONCAT(X,imatrix) 
#define XmatrixY(X,Y) PIKE_CONCAT3(X,imatrix,Y) 
#define PUSH_ELEM( X )  push_int( (INT_TYPE)(X) ) 
#define MATRIX_MPI_TYPE MPI_INT 
#define MATRIX_MPI_SHIFT (18<<3) 
#include <matrix_code.h> 
#undef MATRIX_MPI_SHIFT 
#undef MATRIX_MPI_TYPE 
#undef PUSH_ELEM 
#undef Xmatrix 
#undef matrixX 
#undef XmatrixY 
#undef FTYPE 
#undef PTYPE 
#undef PNAME 
 
#define PNAME "LMatrix" 
#define FTYPE INT64 
#define PTYPE tInt 
#define matrixX(X) PIKE_CONCAT(lmatrix,X) 
#define Xmatrix(X) PIKE_CONCAT(X,lmatrix) 
#define XmatrixY(X,Y) PIKE_CONCAT3(X,lmatrix,Y) 
#define PUSH_ELEM( X )  push_int64( (INT64)(X) ) 
#define MATRIX_MPI_TYPE MPI_LONG_LONG_INT 
#define MATRIX_MPI_SHIFT (19<<3) 
#include <matrix_code.h> 
#undef MATRIX_MPI_SHIFT 
#undef MATRIX_MPI_TYPE 
#undef PUSH_ELEM 
#undef Xmatrix 
#undef matrixX 
#undef XmatrixY 
#undef FTYPE 
#undef PTYPE 
#undef PNAME 
 
#define PNAME "FMatrix" 
#define FTYPE float 
#define PTYPE tFloat 
#define matrixX(X) PIKE_CONCAT(fmatrix,X) 
#define Xmatrix(X) PIKE_CONCAT(X,fmatrix) 
#define XmatrixY(X,Y) PIKE_CONCAT3(X,fmatrix,Y) 
#define PUSH_ELEM( X )  push_float( (FLOAT_TYPE)(X) ) 
#define MATRIX_MPI_TYPE MPI_FLOAT 
#define MATRIX_MPI_SHIFT (20<<3) 
#include <matrix_code.h> 
#undef MATRIX_MPI_SHIFT 
#undef MATRIX_MPI_TYPE 
#undef PUSH_ELEM 
#undef Xmatrix 
#undef matrixX 
#undef XmatrixY 
#undef FTYPE 
#undef PTYPE 
#undef PNAME 
 
#define PNAME "SMatrix" 
#define FTYPE short 
#define PTYPE tInt 
#define matrixX(X) PIKE_CONCAT(smatrix,X) 
#define Xmatrix(X) PIKE_CONCAT(X,smatrix) 
#define XmatrixY(X,Y) PIKE_CONCAT3(X,smatrix,Y) 
#define PUSH_ELEM( X )  push_int( (INT_TYPE)(X) ) 
#define MATRIX_MPI_TYPE MPI_SHORT_INT 
#define MATRIX_MPI_SHIFT (21<<3) 
#include <matrix_code.h> 
#undef MATRIX_MPI_SHIFT 
#undef MATRIX_MPI_TYPE 
#undef PUSH_ELEM 
#undef Xmatrix 
#undef matrixX 
#undef XmatrixY 
#undef FTYPE 
#undef PTYPE 
#undef PNAME 
 
/*! @decl void create(array(array(int|float)) matrix_2d) 
 *! @decl void create(array(int|float) matrix_1d) 
 *!  Initializes the matrix as a 1D or 2D matrix, e.g. 
 *!  @expr{Math.Matrix( ({({1,2}),({3,4})}) )@}. 
 */ 
 
/*! @decl void create(int n,int m) 
 *! @decl void create(int n,int m,string type) 
 *! @decl void create(int n,int m,float|int init) 
 *! Initializes the matrix as to be a @[n]*@[m] matrix with @[init] in 
 *! every value. If no third argument is given, or the third argument 
 *! is @expr{"identity"@}, the matrix will be initialized with all 
 *! zeroes except for the diagonal which will be @expr{1@}. 
 */ 
 
/*! @decl void create(string type,int size) 
 *! When @[type] is @expr{"identity"@} the matrix is initializes as a 
 *! square identity matrix. 
 */ 
 
/*! @decl void create(string type,int size,float rads,Matrix axis) 
 *! @decl void create(string type,int size,float rads,float x,float y,float z) 
 *! 
 *! When @[type] is @expr{"rotate"@} the matrix is initialized as a 
 *! rotation matrix. 
 */ 
 
/* ---------------------------------------------------------------- */ 
 
/*! @decl array(array(float)) cast(string to_what) 
 *! @decl array(array(float)) cast(string to_what) 
 *! 
 *! It is possible to cast the matrix to an array and get back a 
 *! double array of floats with the matrix values. 
 *! @seealso 
 *!   @[vect] 
 */ 
 
/*! @decl array vect() 
 *! Return all the elements of the matrix as an array of numbers 
 */ 
 
/*! @decl Matrix transpose() 
 *! Returns the transpose of the matrix as a new object. 
 */ 
 
/*! @decl float norm() 
 *! @decl float norm2() 
 *! @decl Matrix normv() 
 *!     Norm of the matrix, and the square of the norm 
 *!     of the matrix. (The later method is because you 
 *!     may skip a square root sometimes.) 
 *! 
 *!     This equals |A| or sqrt( A@sub{0@}@sup{2@} + 
 *!     A@sub{1@}@sup{2@} + ... + A@sub{n@}@sup{2@} ). 
 *! 
 *!     It is only usable with 1xn or nx1 matrices. 
 *! 
 *!     @expr{m->normv()@} is equal to @expr{m*(1.0/m->norm())@}, 
 *!     with the exception that the zero vector will still be 
 *!     the zero vector (no error). 
 */ 
 
/*! @decl Matrix `+(object with) 
 *! @decl Matrix ``+(object with) 
 *! @decl Matrix add(object with) 
 *!     Add this matrix to another matrix. A new matrix is returned. 
 *!     The matrices must have the same size. 
 *! 
 *! @decl Matrix `-() 
 *! @decl Matrix `-(object with) 
 *! @decl Matrix ``-(object with) 
 *! @decl Matrix sub(object with) 
 *!     Subtracts this matrix from another. A new matrix is returned. 
 *!     @expr{-m@} is equal to @expr{-1*m@}. 
 */ 
 
/*! @decl Matrix sum() 
 *!     Produces the sum of all the elements in the matrix. 
 */ 
 
/*! @decl Matrix max() 
 *! @decl Matrix min() 
 *! Produces the maximum or minimum value of all the elements in the 
 *! matrix. 
 */ 
 
/*! @decl Matrix `*(object with) 
 *! @decl Matrix ``*(object with) 
 *! @decl Matrix mult(object with) 
 *!     Matrix multiplication. 
 */ 
 
/*! @decl Matrix cross(object with) 
 *!     Matrix cross-multiplication. 
 */ 
 
 
/*! @decl float dot_product(object with) 
 *!     Matrix dot product. 
 */ 
 
/*! @decl Matrix convolve(object with) 
 *!     Convolve called matrix with the argument. 
 */ 
 
/*! @decl int xsize() 
 *!     Returns the width of the matrix. 
 */ 
 
/*! @decl int ysize() 
 *!     Returns the height of the matrix. 
 */ 
 
/*! @endclass 
 */ 
 
/*! @class FMatrix 
 *! @inherit Matrix 
 *! Matrix representation with single precision floating point values. 
 *! @endclass 
 */ 
 
/*! @class LMatrix 
 *! @inherit Matrix 
 *! Matrix representation with 64 bit integer values. 
 *! @endclass 
 */ 
 
/*! @class IMatrix 
 *! @inherit Matrix 
 *! Matrix representation with 32 bit integer values. 
 *! @endclass 
 */ 
 
/*! @class SMatrix 
 *! @inherit Matrix 
 *! Matrix representation with 16 bit integer values. 
 *! @endclass 
 */ 
 
/*! @endmodule 
 */