libStatGen Software 1
Loading...
Searching...
No Matches
Matrix Class Reference
Collaboration diagram for Matrix:

Public Member Functions

 Matrix (Matrix &m)
 
 Matrix (Matrix &m, const char *name)
 
 Matrix (int n, int m)
 
 Matrix (const char *name)
 
 Matrix (const char *name, int n, int m)
 
void Dimension (int m, int n)
 
void Dimension (int m, int n, double value)
 
void GrowTo (int m, int n)
 
void GrowTo (int m, int n, double value)
 
void SetLabel (const char *name)
 
void SetColumnLabel (int n, const char *name)
 
const char * GetColumnLabel (int n)
 
void SetColWidth (int n, int w)
 
void SetColPrecision (int n, int p)
 
void CopyLabels (Matrix &m)
 
void Negate ()
 
void Identity ()
 
void Zero ()
 
void Set (double k)
 
void Copy (const Matrix &m)
 
void Transpose (const Matrix &m)
 
void Add (const Matrix &m)
 
void AddMultiple (double k, const Matrix &m)
 
void Product (const Matrix &left, const Matrix &right)
 
void Add (double k)
 
void Multiply (double k)
 
void Reduce (double tol=0.0)
 
Vectoroperator[] (int i)
 
const Vectoroperator[] (int i) const
 
void DeleteRow (int r)
 
void DeleteColumn (int c)
 
void SwapRows (int r1, int r2)
 
void SwapColumns (int c1, int c2)
 
void MultiplyRow (int r1, double k)
 
void AddRows (int r1, int r2)
 
void AddRows (double k, int r1, int r2)
 
void Sort ()
 
void Print (FILE *f, int maxRows=-1, int maxCols=-1)
 
void PrintUpper (FILE *f, int maxRows=-1, int maxCols=-1, bool print_diag=false)
 
void PrintLower (FILE *f, int maxRows=-1, int maxCols=-1, bool print_diag=false)
 
void SetupPrint (FILE *f, int r, int c, int &column_zero, int *precision, int *width)
 
void Read (FILE *f)
 
Matrixoperator= (const Matrix &rhs)
 
bool operator== (const Matrix &rhs) const
 
bool operator!= (const Matrix &rhs) const
 
Matrixoperator*= (double rhs)
 
Matrixoperator/= (double rhs)
 
void StackBottom (const Matrix &m)
 
void StackLeft (const Matrix &m)
 
void Swap (Matrix &m)
 
double Min () const
 
double Max () const
 
double Mean () const
 
double SafeMin () const
 
double SafeMax () const
 
double SafeMean () const
 
int SafeCount () const
 
VectorLast ()
 

Public Attributes

String label
 
ColumnExtrasextras
 
int rows
 
int cols
 
int size
 
int extraSize
 
Vector ** data
 

Detailed Description

Definition at line 76 of file MathMatrix.h.

Constructor & Destructor Documentation

◆ Matrix() [1/6]

Matrix::Matrix ( )
inline

Definition at line 84 of file MathMatrix.h.

85 {
86 Init();
87 }

◆ Matrix() [2/6]

Matrix::Matrix ( Matrix m)
inline

Definition at line 88 of file MathMatrix.h.

89 {
90 Init();
91 Copy(m);
92 }

◆ Matrix() [3/6]

Matrix::Matrix ( Matrix m,
const char *  name 
)
inline

Definition at line 93 of file MathMatrix.h.

94 {
95 Init();
96 Copy(m);
97 SetLabel(name);
98 }

◆ Matrix() [4/6]

Matrix::Matrix ( int  n,
int  m 
)
inline

Definition at line 99 of file MathMatrix.h.

100 {
101 Init();
102 Dimension(n, m);
103 }

◆ Matrix() [5/6]

Matrix::Matrix ( const char *  name)
inline

Definition at line 104 of file MathMatrix.h.

105 {
106 Init();
107 SetLabel(name);
108 }

◆ Matrix() [6/6]

Matrix::Matrix ( const char *  name,
int  n,
int  m 
)
inline

Definition at line 109 of file MathMatrix.h.

110 {
111 Init();
112 Dimension(n, m);
113 SetLabel(name);
114 }

◆ ~Matrix()

Matrix::~Matrix ( )

Definition at line 30 of file MathMatrix.cpp.

31{
32 // printf("Deleting Matrix %s...\n", (const char *) label);
33
34 for (int i=0; i<size; i++)
35 delete data[i];
36
37 if (size)
38 delete [] data;
39
40 if (extraSize)
41 delete [] extras;
42}

Member Function Documentation

◆ Add() [1/2]

void Matrix::Add ( const Matrix m)

Definition at line 195 of file MathMatrix.cpp.

196{
197 if ((rows != m.rows) && (cols != m.cols))
198 error("Matrix.Add - Attempted to add incompatible matrices\n"
199 "Matrices - %s [%d, %d] + %s [%d, %d]\n",
200 (const char *) label, rows, cols,
201 (const char *) m.label, m.rows, m.cols);
202
203 for (int i = 0; i < rows; i++)
204 for (int j = 0; j < cols; j++)
205 (*(data[i]))[j] += m[i][j];
206}

◆ Add() [2/2]

void Matrix::Add ( double  k)

Definition at line 181 of file MathMatrix.cpp.

182{
183 for (int i = 0; i < rows; i++)
184 for (int j = 0; j < cols; j++)
185 (*(data[i]))[j] += k;
186}

◆ AddMultiple()

void Matrix::AddMultiple ( double  k,
const Matrix m 
)

Definition at line 208 of file MathMatrix.cpp.

209{
210 if ((rows != m.rows) && (cols != m.cols))
211 error("Matrix.AddMultiple - Attempted to add incompatible matrices\n"
212 "Matrices - %s [%d, %d] + k * %s [%d, %d]\n",
213 (const char *) label, rows, cols,
214 (const char *) m.label, m.rows, m.cols);
215
216 for (int i = 0; i < rows; i++)
217 for (int j = 0; j < cols; j++)
218 (*(data[i]))[j] += k * m[i][j];
219}

◆ AddRows() [1/2]

void Matrix::AddRows ( double  k,
int  r1,
int  r2 
)

Definition at line 239 of file MathMatrix.cpp.

240{
241 Vector v(*(data[r1]));
242
243 v.Multiply(k);
244 data[r2]->Add(v);
245}

◆ AddRows() [2/2]

void Matrix::AddRows ( int  r1,
int  r2 
)

Definition at line 252 of file MathMatrix.cpp.

253{
254 data[r2]->Add(*(data[r1]));
255}

◆ Copy()

void Matrix::Copy ( const Matrix m)

Definition at line 162 of file MathMatrix.cpp.

163{
164 Dimension(m.rows, m.cols);
165
166 if (m.data != NULL)
167 for (int i = 0; i < rows; i++)
168 for (int j = 0; j < cols; j++)
169 (*this)[i][j] = m[i][j];
170}

◆ CopyLabels()

void Matrix::CopyLabels ( Matrix m)

Definition at line 407 of file MathMatrix.cpp.

408{
409 for (int i = 0; i < rows; i++)
410 if (i < M.rows)
411 data[i]->SetLabel(M[i].label);
412
413 for (int i = 0; i < cols; i++)
414 if (i < M.cols)
415 SetColumnLabel(i, M.GetColumnLabel(i));
416}

◆ DeleteColumn()

void Matrix::DeleteColumn ( int  c)

Definition at line 314 of file MathMatrix.cpp.

315{
316 for (int i = 0; i < rows; i++)
317 data[i] -> DeleteDimension(c);
318
319 for (int i = c + 1; i < cols; i++)
320 extras[i-1] = extras[i];
321
322 cols--;
323}

◆ DeleteRow()

void Matrix::DeleteRow ( int  r)

Definition at line 303 of file MathMatrix.cpp.

304{
305 Vector * temp = data[r];
306
307 for (int i = r + 1; i < rows; i++)
308 data[i-1] = data[i];
309
310 data[rows - 1] = temp;
311 rows--;
312}

◆ Dimension() [1/2]

void Matrix::Dimension ( int  m,
int  n 
)

Definition at line 59 of file MathMatrix.cpp.

60{
61 if (n == cols && m == rows)
62 return;
63
64 if (n > extraSize)
65 {
66 int newSize = (n + alloc) / alloc * alloc;
67 ColumnExtras * newExtras = new ColumnExtras [newSize];
68
69 if (extras != NULL)
70 for (int i = 0; i < extraSize; i++)
71 newExtras[i] = extras[i];
72
73 if (extraSize)
74 delete [] extras;
75
76 extraSize = newSize;
77 extras = newExtras;
78 }
79
80 if (m > size)
81 {
82 int newSize = (m + alloc) / alloc * alloc;
83 Vector ** newData = new Vector * [newSize];
84
85 if (data != NULL)
86 for (int i = 0; i < size; i++)
87 newData[i] = data[i];
88
89 for (int i = size; i < newSize; i++)
90 newData[i] = new Vector(n);
91
92 if (size)
93 delete [] data;
94
95 size = newSize;
96 data = newData;
97 }
98
99 if (cols != n)
100 for (int i = 0; i < rows; i++)
101 data[i]->Dimension(n);
102
103 if (rows != m)
104 for (int i = rows; i < m; i++)
105 data[i]->Dimension(n);
106
107 rows = m;
108 cols = n;
109}

◆ Dimension() [2/2]

void Matrix::Dimension ( int  m,
int  n,
double  value 
)

Definition at line 111 of file MathMatrix.cpp.

112{
113 int originalRows = rows;
114 int originalColumns = cols;
115
116 Dimension(m, n);
117
118 if (rows > originalRows)
119 for (int i = originalRows; i < rows; i++)
120 data[i]->Set(value);
121
122 if (cols > originalColumns)
123 for (int i = 0; i < originalRows; i++)
124 for (int j = originalColumns; j < cols; j++)
125 data[i]->data[j] = value;
126}

◆ GetColumnLabel()

const char * Matrix::GetColumnLabel ( int  n)
inline

Definition at line 133 of file MathMatrix.h.

134 {
135 return extras[n].label;
136 }

◆ GrowTo() [1/2]

void Matrix::GrowTo ( int  m,
int  n 
)
inline

Definition at line 119 of file MathMatrix.h.

120 {
121 Dimension(m > rows ? m : rows, n > cols ? n : cols);
122 }

◆ GrowTo() [2/2]

void Matrix::GrowTo ( int  m,
int  n,
double  value 
)
inline

Definition at line 123 of file MathMatrix.h.

124 {
125 Dimension(m > rows ? m : rows, n > cols ? n : cols, value);
126 }

◆ Identity()

void Matrix::Identity ( )

Definition at line 135 of file MathMatrix.cpp.

136{
137 if (rows != cols)
138 error("Matrix.Identity - Identity matrices must be square");
139
140 for (int i = 0; i < rows; i++)
141 for (int j = 0; j < cols; j++)
142 if (i == j)
143 (*(data[i]))[j] = 1.0;
144 else
145 (*(data[i]))[j] = 0.0;
146}

◆ Last()

Vector & Matrix::Last ( )
inline

Definition at line 247 of file MathMatrix.h.

248 {
249 return *(data[rows - 1]);
250 }

◆ Max()

double Matrix::Max ( ) const

Definition at line 555 of file MathMatrix.cpp.

556{
557 if (rows == 0 || cols == 0)
558 return 0.0;
559
560 double maximum = data[0]->Max();
561
562 for (int i = 1; i < rows; i++)
563 maximum = max(data[i]->Max(), maximum);
564
565 return maximum;
566}

◆ Mean()

double Matrix::Mean ( ) const

Definition at line 568 of file MathMatrix.cpp.

569{
570 if (rows == 0 || cols == 0)
571 return 0.0;
572
573 double sum = data[0]->Sum();
574
575 for (int i = 1; i < rows; i++)
576 sum += data[i]->Sum();
577
578 return sum / (rows * cols);
579}

◆ Min()

double Matrix::Min ( ) const

Definition at line 542 of file MathMatrix.cpp.

543{
544 if (rows == 0 || cols == 0)
545 return 0.0;
546
547 double minimum = data[0]->Min();
548
549 for (int i = 1; i < rows; i++)
550 minimum = min(data[i]->Min(), minimum);
551
552 return minimum;
553}

◆ Multiply()

void Matrix::Multiply ( double  k)

Definition at line 188 of file MathMatrix.cpp.

189{
190 for (int i = 0; i < rows; i++)
191 for (int j = 0; j < cols; j++)
192 (*(data[i]))[j] *= k;
193}

◆ MultiplyRow()

void Matrix::MultiplyRow ( int  r1,
double  k 
)

Definition at line 247 of file MathMatrix.cpp.

248{
249 data[r1]->Multiply(k);
250}

◆ Negate()

void Matrix::Negate ( )

Definition at line 155 of file MathMatrix.cpp.

156{
157 for (int i = 0; i < rows; i++)
158 for (int j = 0; j < cols; j++)
159 (*(data[i]))[j] = -(*(data[i]))[j];
160}

◆ operator!=()

bool Matrix::operator!= ( const Matrix rhs) const
inline

Definition at line 210 of file MathMatrix.h.

211 {
212 return !(*this == rhs);
213 }

◆ operator*=()

Matrix & Matrix::operator*= ( double  rhs)
inline

Definition at line 215 of file MathMatrix.h.

216 {
217 Multiply(rhs);
218 return *this;
219 }

◆ operator/=()

Matrix & Matrix::operator/= ( double  rhs)
inline

Definition at line 220 of file MathMatrix.h.

221 {
222 Multiply(1.0/rhs);
223 return *this;
224 }

◆ operator=()

Matrix & Matrix::operator= ( const Matrix rhs)
inline

Definition at line 203 of file MathMatrix.h.

204 {
205 Copy(rhs);
206 return *this;
207 }

◆ operator==()

bool Matrix::operator== ( const Matrix rhs) const

Definition at line 481 of file MathMatrix.cpp.

482{
483 if (rhs.rows != rows || rhs.cols != cols) return false;
484
485 for (int i = 0; i < rows; i++)
486 if ((*this)[i] != rhs[i])
487 return false;
488 return true;
489}

◆ operator[]() [1/2]

Vector & Matrix::operator[] ( int  i)
inline

Definition at line 165 of file MathMatrix.h.

166 {
167 assert(i < rows);
168 return *(data[i]);
169 }

◆ operator[]() [2/2]

const Vector & Matrix::operator[] ( int  i) const
inline

Definition at line 171 of file MathMatrix.h.

172 {
173 assert(i < rows);
174 return *(data[i]);
175 }

◆ Print()

void Matrix::Print ( FILE *  f,
int  maxRows = -1,
int  maxCols = -1 
)

Definition at line 370 of file MathMatrix.cpp.

371{
372 if (r == -1 || r > rows) r = rows;
373 if (c == -1 || c > cols) c = cols;
374
375 char dimensions[30];
376
377 sprintf(dimensions, "[%d x %d]", r, c);
378
379 int columnZero = label.Length() > 15 ? label.Length() : 15;
380
381 fprintf(f, "\n%*s =\n%*s ", columnZero, (const char *) label,
382 columnZero, dimensions);
383
384 int * precision = new int [c + 1];
385 int * width = new int [c + 1];
386
387 for (int j = 0; j < c; j++)
388 {
389 precision[j] = extras[j].GetPrecision();
390 width[j] = extras[j].GetWidth();
391 fprintf(f, "%*s ", width[j], (const char *) extras[j].label);
392 }
393
394 for (int i = 0; i < r; i++)
395 {
396 fprintf(f, "\n%*s ", columnZero, (const char *) data[i]->label);
397 for (int j = 0; j < c; j++)
398 fprintf(f, "%*.*f ", width[j], precision[j], (*this)[i][j]);
399 }
400
401 fprintf(f, "\n");
402
403 delete [] precision;
404 delete [] width;
405}

◆ PrintLower()

void Matrix::PrintLower ( FILE *  f,
int  maxRows = -1,
int  maxCols = -1,
bool  print_diag = false 
)

Definition at line 683 of file MathMatrix.cpp.

684{
685 if (r == -1 || r > rows) r = rows;
686 if (c == -1 || c > cols) c = cols;
687
688 String dimensions;
689 dimensions.printf("[%d x %d]", r, c);
690
691 int columnZero = label.Length() > 15 ? label.Length() : 15;
692
693 fprintf(f, "\n%*s =\n%*s ", columnZero, (const char *) label,
694 columnZero, (const char *) dimensions);
695
696 int * precision = new int [c + 1];
697 int * width = new int [c + 1];
698
699 for (int j = 0; j < c; j++)
700 {
701 precision[j] = extras[j].GetPrecision();
702 width[j] = extras[j].GetWidth();
703 fprintf(f, "%*s ", width[j], (const char *) extras[j].label);
704 }
705
706 int upper = print_diag ? 1 : 0;
707
708 for (int i = 0; i < r ; i++)
709 {
710 fprintf(f, "\n%*s ", columnZero, (const char *) data[i]->label);
711 for (int j = 0; j < upper; j++)
712 fprintf(f, "%*.*f ", width[j], precision[j],(*this)[i][j]);
713 for (int j = upper; j < c; j++)
714 fprintf(f, "%*.*s ", width[j], precision[j]," ");
715
716 upper++;
717 }
718
719 fprintf(f, "\n");
720
721 delete [] precision;
722 delete [] width;
723}

◆ PrintUpper()

void Matrix::PrintUpper ( FILE *  f,
int  maxRows = -1,
int  maxCols = -1,
bool  print_diag = false 
)

Definition at line 657 of file MathMatrix.cpp.

658{
659 int columnZero;
660 int * precision = NULL, * width = NULL; // Initialization avoids compiler warnings
661
662 SetupPrint(f, r, c, columnZero, precision, width);
663
664 int upper = print_diag ? 0 : 1;
665 for (int i = 0; i < r ; i++)
666 {
667 fprintf(f, "\n%*s ", columnZero, (const char *) data[i]->label);
668
669 for (int j = 0; j < upper; j++)
670 fprintf(f, "%*.*s ", width[j], precision[j], " ");
671 for (int j = upper; j < c; j++)
672 fprintf(f, "%*.*f ", width[j], precision[j], (*this)[i][j]);
673
674 upper++;
675 }
676
677 fprintf(f, "\n");
678
679 delete [] precision;
680 delete [] width;
681}

◆ Product()

void Matrix::Product ( const Matrix left,
const Matrix right 
)

Definition at line 222 of file MathMatrix.cpp.

223{
224 if (l.cols != r.rows)
225 error("Matrix.Multiply - Attempted to multiply incompatible matrices\n"
226 "Matrices - %s [%d, %d] + %s [%d, %d]\n",
227 (const char *) l.label, l.rows, l.cols,
228 (const char *) r.label, r.rows, r.cols);
229
230 Dimension(l.rows, r.cols);
231 Zero();
232
233 for (int k = 0; k < l.cols; k++)
234 for (int i = 0; i < rows; i++)
235 for (int j = 0; j < cols; j++)
236 (*(data[i]))[j] += l[i][k] * r[k][j];
237}

◆ Read()

void Matrix::Read ( FILE *  f)

Definition at line 339 of file MathMatrix.cpp.

340{
341 int r, c;
342 char buffer[100];
343 int numItems = 0;
344
345 numItems = fscanf(f, " %s =", buffer);
346 if(numItems != 1) { }
347 buffer[strlen(buffer) - 1] = 0;
348 SetLabel(buffer);
349
350 numItems = fscanf(f, " [ %d x %d ]", &r, &c);
351 if(numItems != 2) { }
352 Dimension(r, c);
353
354 for (int c = 0; c < cols; c++)
355 {
356 numItems = fscanf(f, " %s", buffer);
357 if(numItems != 1) { }
358 SetColumnLabel(c, buffer);
359 }
360
361 for (int r = 0; r < rows; r++)
362 for (int c = 0; c < cols; c++)
363 {
364 numItems = fscanf(f, " %lf", &((*this)[r][c]));
365 if(numItems != 1) { }
366 }
367}

◆ Reduce()

void Matrix::Reduce ( double  tol = 0.0)

Definition at line 257 of file MathMatrix.cpp.

258{
259 double pivot;
260 int pivotr = 0; // Initializing pivotr is not necessary, but avoids warnings
261 int r = 0; // the row we are currently reducing
262
263 for (int j = 0; j < cols; j++)
264 {
265 if (r > rows)
266 return;
267
268 pivot = 0.0;
269 for (int i = r; i < rows; i++)
270 if (fabs((*this)[i][j]) > pivot)
271 {
272 pivot = fabs((*this)[i][j]);
273 pivotr = i;
274 }
275
276 if (pivot <= tol)
277 {
278 for (int i = r; i < rows; i++)
279 (*this)[i][j] = 0.0;
280 continue;
281 }
282
283 SwapRows(pivotr, r);
284
285 double scale = (*this)[r][j];
286
287 (*this)[r][j] = 1.0;
288 for (int k = j+1; k < cols; k++)
289 (*this)[r][k] /= scale;
290
291 for (int i = r + 1; r < rows; i++)
292 {
293 scale = (*this)[i][j];
294 (*this)[i][j] = 0.0;
295 for (int k = j+1; k < cols; k++)
296 (*this)[i][k] -= (*this)[r][k] * scale;
297 }
298
299 r++;
300 }
301}

◆ SafeCount()

int Matrix::SafeCount ( ) const

Definition at line 647 of file MathMatrix.cpp.

648{
649 int total = 0;
650
651 for (int i = 0; i < rows; i++)
652 total += data[i]->SafeCount();
653
654 return total;
655}

◆ SafeMax()

double Matrix::SafeMax ( ) const

Definition at line 606 of file MathMatrix.cpp.

607{
608 double hi = (rows > 0 && cols > 0) ? _NAN_ : 0.0;
609
610 int i, j;
611
612 for (i = 0; i < rows; i++)
613 {
614 for (j = 0; j < cols; j++)
615 if (data[i]->data[j] != _NAN_)
616 {
617 hi = data[i]->data[j];
618 break;
619 }
620 if (j != cols) break;
621 }
622
623 for (; i < rows; i++, j = 0)
624 for (; j < cols; j++)
625 if (data[i]->data[j] > hi && data[i]->data[j] != _NAN_)
626 hi = data[i]->data[j];
627
628 return hi;
629}

◆ SafeMean()

double Matrix::SafeMean ( ) const

Definition at line 631 of file MathMatrix.cpp.

632{
633 double sum = 0.0;
634 int count = 0;
635
636 for (int i = 0; i < rows; i++)
637 for (int j = 0; j < cols; j++)
638 if ((*this)[i][j] != _NAN_)
639 {
640 sum += (*this)[i][j];
641 count ++;
642 }
643
644 return (count) ? sum / count : 0.0;
645}

◆ SafeMin()

double Matrix::SafeMin ( ) const

Definition at line 581 of file MathMatrix.cpp.

582{
583 double lo = (rows > 0 && cols > 0) ? _NAN_ : 0.0;
584
585 int i, j;
586
587 for (i = 0; i < rows; i++)
588 {
589 for (j = 0; j < cols; j++)
590 if (data[i]->data[j] != _NAN_)
591 {
592 lo = data[i]->data[j];
593 break;
594 }
595 if (j != cols) break;
596 }
597
598 for (; i < rows; i++, j = 0)
599 for (; j < cols; j++)
600 if (data[i]->data[j] < lo && data[i]->data[j] != _NAN_)
601 lo = data[i]->data[j];
602
603 return lo;
604}

◆ Set()

void Matrix::Set ( double  k)

Definition at line 148 of file MathMatrix.cpp.

149{
150 for (int i = 0; i < rows; i++)
151 for (int j = 0; j < cols; j++)
152 (*(data[i]))[j] = k;
153}

◆ SetColPrecision()

void Matrix::SetColPrecision ( int  n,
int  p 
)
inline

Definition at line 141 of file MathMatrix.h.

142 {
143 extras[n].SetPrecision(p);
144 }

◆ SetColumnLabel()

void Matrix::SetColumnLabel ( int  n,
const char *  name 
)
inline

Definition at line 129 of file MathMatrix.h.

130 {
131 extras[n].SetLabel(name);
132 }

◆ SetColWidth()

void Matrix::SetColWidth ( int  n,
int  w 
)
inline

Definition at line 137 of file MathMatrix.h.

138 {
139 extras[n].SetWidth(w);
140 }

◆ SetLabel()

void Matrix::SetLabel ( const char *  name)

Definition at line 52 of file MathMatrix.cpp.

53{
54 label = '[';
55 label += name;
56 label += ']';
57}

◆ SetupPrint()

void Matrix::SetupPrint ( FILE *  f,
int  r,
int  c,
int &  column_zero,
int *  precision,
int *  width 
)

Definition at line 726 of file MathMatrix.cpp.

727{
728 if (r == -1 || r > rows) r = rows;
729 if (c == -1 || c > cols) c = cols;
730
731 String dimensions;
732 dimensions.printf("[%d x %d]", r, c);
733
734 column_zero = label.Length() > 15 ? label.Length() : 15;
735
736 fprintf(f, "\n%*s =\n%*s ", column_zero, (const char *) label,
737 column_zero, (const char *) dimensions);
738
739 precision = new int [c + 1];
740 width = new int [c + 1];
741
742 for (int j = 0; j < c; j++)
743 {
744 precision[j] = extras[j].GetPrecision();
745 width[j] = extras[j].GetWidth();
746 fprintf(f, "%*s ", width[j], (const char *) extras[j].label);
747 }
748}

◆ Sort()

void Matrix::Sort ( )

Definition at line 476 of file MathMatrix.cpp.

477{
478 QuickSort(data, rows, sizeof(Vector *), COMPAREFUNC CompareRows);
479}

◆ StackBottom()

void Matrix::StackBottom ( const Matrix m)

Definition at line 491 of file MathMatrix.cpp.

492{
493 if (m.cols != cols)
494 error("Attempted to stack matrices with different number of columns");
495
496 int end = rows;
497
498 Dimension(rows + m.rows, cols);
499
500 for (int i = 0; i < m.rows; i++)
501 *(data[i + end]) = m[i];
502}

◆ StackLeft()

void Matrix::StackLeft ( const Matrix m)

Definition at line 504 of file MathMatrix.cpp.

505{
506 if (m.rows != rows)
507 error("Attempted to stack matrics with different numbers of rows");
508
509 for (int i = 0; i < rows; i++)
510 data[i]->Stack(m[i]);
511
512 Dimension(rows, cols + m.cols);
513}

◆ Swap()

void Matrix::Swap ( Matrix m)

Definition at line 515 of file MathMatrix.cpp.

516{
517 label.Swap(m.label);
518
519 ColumnExtras * tmpExtras = extras;
520 extras = m.extras;
521 m.extras = tmpExtras;
522
523 int swap;
524 swap = rows;
525 rows = m.rows;
526 m.rows = swap;
527 swap = cols;
528 cols = m.cols;
529 m.cols = swap;
530 swap = size;
531 size = m.size;
532 m.size = swap;
533 swap = extraSize;
534 extraSize = m.extraSize;
535 m.extraSize = swap;
536
537 Vector ** tmpData = data;
538 data = m.data;
539 m.data = tmpData;
540}

◆ SwapColumns()

void Matrix::SwapColumns ( int  c1,
int  c2 
)

Definition at line 325 of file MathMatrix.cpp.

326{
327 double temp;
328
329 for (int i = 0; i < rows; i++)
330 {
331 temp = (*data[i])[c1];
332 (*data[i])[c1] = (*data[i])[c2];
333 (*data[i])[c2] = temp;
334 }
335
336 extras[c1].Swap(extras[c2]);
337}

◆ SwapRows()

void Matrix::SwapRows ( int  r1,
int  r2 
)
inline

Definition at line 180 of file MathMatrix.h.

181 {
182 Vector * temp = data[r1];
183 data[r1] = data[r2];
184 data[r2] = temp;
185 };

◆ Transpose()

void Matrix::Transpose ( const Matrix m)

Definition at line 172 of file MathMatrix.cpp.

173{
174 Dimension(m.cols, m.rows);
175
176 for (int i = 0; i < rows; i++)
177 for (int j = 0; j < cols; j++)
178 (*(data[i]))[j] = m[j][i];
179}

◆ Zero()

void Matrix::Zero ( )

Definition at line 128 of file MathMatrix.cpp.

129{
130 for (int i = 0; i < rows; i++)
131 for (int j = 0; j < cols; j++)
132 (*(data[i]))[j] = 0.0;
133}

Member Data Documentation

◆ cols

int Matrix::cols

Definition at line 81 of file MathMatrix.h.

◆ data

Vector** Matrix::data

Definition at line 82 of file MathMatrix.h.

◆ extras

ColumnExtras* Matrix::extras

Definition at line 80 of file MathMatrix.h.

◆ extraSize

int Matrix::extraSize

Definition at line 81 of file MathMatrix.h.

◆ label

String Matrix::label

Definition at line 79 of file MathMatrix.h.

◆ rows

int Matrix::rows

Definition at line 81 of file MathMatrix.h.

◆ size

int Matrix::size

Definition at line 81 of file MathMatrix.h.


The documentation for this class was generated from the following files: