41 template <
class nr_type_t>
50 template <
class nr_type_t>
54 data =
new nr_type_t[s *
s];
55 memset (
data, 0,
sizeof (nr_type_t) * s * s);
62 template <
class nr_type_t>
67 data =
new nr_type_t[r *
c];
68 memset (
data, 0,
sizeof (nr_type_t) * r * c);
75 template <
class nr_type_t>
82 if (rows > 0 && cols > 0) {
83 data =
new nr_type_t[rows * cols];
84 memcpy (
data, m.data, sizeof (nr_type_t) * rows * cols);
90 template <
class nr_type_t>
97 if (rows > 0 && cols > 0) {
98 data =
new nr_type_t[rows * cols];
99 memcpy (
data, m.data, sizeof (nr_type_t) * rows * cols);
106 template <
class nr_type_t>
112 template <
class nr_type_t>
114 assert (r >= 0 && r < rows && c >= 0 && c < cols);
115 return data[r * cols +
c];
119 template <
class nr_type_t>
121 assert (r >= 0 && r < rows && c >= 0 && c < cols);
122 data[r * cols +
c] = z;
126 template <
class nr_type_t>
128 for (
int i = 0;
i < rows * cols;
i++)
data[
i] = z;
132 template <
class nr_type_t>
134 assert (r >= 0 && r < rows);
136 nr_type_t * dst = res.
getData ();
137 nr_type_t * src = &
data[r * cols];
138 memcpy (dst, src,
sizeof (nr_type_t) * cols);
143 template <
class nr_type_t>
145 assert (r >= 0 && r < rows && v.
getSize () == cols);
146 nr_type_t * dst = &
data[r * cols];
147 nr_type_t * src = v.
getData ();
148 memcpy (dst, src,
sizeof (nr_type_t) * cols);
152 template <
class nr_type_t>
154 assert (c >= 0 && c < cols);
156 nr_type_t * dst = res.
getData ();
157 nr_type_t * src = &
data[
c];
158 for (
int r = 0; r < rows; r++, src += cols, dst++) *dst = *src;
163 template <
class nr_type_t>
165 assert (c >= 0 && c < cols && v.
getSize () == rows);
166 nr_type_t * dst = &
data[
c];
167 nr_type_t * src = v.
getData ();
168 for (
int r = 0; r < rows; r++, src++, dst += cols) *dst = *src;
172 template <
class nr_type_t>
174 assert (r1 >= 0 && r2 >= 0 && r1 < rows && r2 < rows);
175 nr_type_t *
s =
new nr_type_t[cols];
176 int len =
sizeof (nr_type_t) * cols;
177 memcpy (s, &
data[r1 * cols], len);
178 memcpy (&
data[r1 * cols], &
data[r2 * cols], len);
179 memcpy (&
data[r2 * cols], s, len);
184 template <
class nr_type_t>
186 assert (c1 >= 0 && c2 >= 0 && c1 < cols && c2 < cols);
188 for (
int r = 0; r < rows * cols; r += cols) {
196 template <
class nr_type_t>
198 nr_double_t MaxPivot;
206 e = teye<nr_type_t> (
n);
209 for (i = 0; i <
n; i++) {
211 for (MaxPivot = 0, pivot = r = i; r <
n; r++) {
212 if (
abs (b.
get (r, i)) > MaxPivot) {
213 MaxPivot =
abs (b.
get (r, i));
218 assert (MaxPivot != 0);
226 for (c = 0; c <
n; c++) {
227 b.
set (i, c, b.
get (i, c) / f);
228 e.
set (i, c, e.
get (i, c) / f);
232 for (r = 0; r <
n; r++) {
235 for (c = 0; c <
n; c++) {
236 b.
set (r, c, b.
get (r, c) - f * b.
get (i, c));
237 e.
set (r, c, e.
get (r, c) - f * e.
get (i, c));
246 template <
class nr_type_t>
249 for (
int r = 0; r <
n; r++) res.
set (r, r, 1);
254 template <
class nr_type_t>
257 nr_type_t * src = a.
getData ();
258 nr_type_t * dst =
data;
259 for (
int i = 0;
i < rows * cols;
i++) *dst++ += *src++;
264 template <
class nr_type_t>
267 nr_type_t * src = a.
getData ();
268 nr_type_t * dst =
data;
269 for (
int i = 0;
i < rows * cols;
i++) *dst++ -= *src++;
274 template <
class nr_type_t>
280 for (r = 0; r < a.
getRows (); r++) {
281 for (c = 0; c < b.
getCols (); c++) {
282 for (i = 0, z = 0; i <
n; i++) z += a.
get (r, i) * b.
get (i, c);
290 template <
class nr_type_t>
297 for (r = 0; r <
n; r++) {
298 for (c = 0, z = 0; c <
n; c++) z += a.
get (r, c) * b.
get (c);
305 template <
class nr_type_t>
312 for (c = 0; c <
n; c++) {
313 for (r = 0, z = 0; r <
n; r++) z += a.
get (r) * b.
get (r, c);
320 template <
class nr_type_t>
323 for (
int r = 0; r < getRows (); r++)
324 for (
int c = 0;
c < r;
c++) {
326 set (r,
c,
get (
c, r));
332 template <
class nr_type_t>
334 for (
int i = 0;
i < rows * cols;
i++)
341 template <
class nr_type_t>
343 for (
int r = 0; r < rows; r++) {
344 for (
int c = 0;
c < cols;
c++) {
347 c != cols - 1 ?
" " :
"");
349 fprintf (stderr,
"%+.2e%+.2ei%s", (
double)
real (
get (r,
c)),
350 (
double)
imag (
get (r,
c)),
c != cols - 1 ?
" " :
"");