SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseMatrix.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2010 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file DenseMatrix.h
33 ///@brief Dense matrices
34 ///
35 ///@author
36 /// Steven G. Parker
37 /// Department of Computer Science
38 /// University of Utah
39 ///@date October 1994
40 ///
41 
42 #ifndef CORE_DATATYPES_DENSEMATRIX_H
43 #define CORE_DATATYPES_DENSEMATRIX_H 1
44 
45 #include <Core/Datatypes/Matrix.h>
46 #include <Core/Util/FancyAssert.h>
47 
50 
51 #if defined(HAVE_LAPACK)
52 #include <Core/Math/sci_lapack.h>
53 #endif
54 
55 #include <cfloat>
56 #include <vector>
57 
58 #include <Core/Datatypes/share.h>
59 
60 namespace SCIRun {
61 
62  class Transform;
63  class Vector;
64  class Point;
65  class Tensor;
66 
67 template <typename T>
68 class DenseMatrixGeneric : public Matrix<T> {
69 
70 public:
71  /// Constructors
74  DenseMatrixGeneric(size_type r, size_type c, T value);
76  explicit DenseMatrixGeneric(T scalar);
77  explicit DenseMatrixGeneric(const Transform &t);
78  explicit DenseMatrixGeneric(const Vector& vec);
79  explicit DenseMatrixGeneric(const Point& pnt);
80  explicit DenseMatrixGeneric(const Tensor& tens);
81 
82  /// Destructor
83  virtual ~DenseMatrixGeneric();
84 
85  /// Public member functions
86  virtual DenseMatrixGeneric* clone() const;
88 
89  virtual DenseMatrix *dense();
90  virtual SparseRowMatrix *sparse();
91  virtual ColumnMatrix *column();
93 
94  virtual T* get_data_pointer() const;
95  virtual size_type get_data_size() const;
96 
97  /// slow setters/getter for polymorphic operations
98  virtual void zero();
99  virtual T get(index_type r, index_type c) const;
100  virtual void put(index_type r, index_type c, T val);
101  virtual void add(index_type r, index_type c, T val);
102 
103  virtual T min();
104  virtual T max();
105  virtual int compute_checksum();
106 
107  virtual void getRowNonzerosNoCopy(index_type r, size_type &size,
108  index_type &stride,
109  index_type *&cols, T *&vals);
110 
111  virtual DenseMatrixGeneric* make_transpose() const;
112  virtual void mult(const ColumnMatrix& x, ColumnMatrix& b,
113  index_type beg=-1, index_type end=-1,
114  int spVec=0) const;
115  virtual void mult_transpose(const ColumnMatrix& x, ColumnMatrix& b,
116  index_type beg=-1, index_type end=-1,
117  int spVec=0) const;
119  index_type r2, index_type c2);
120 
121  void multiply(ColumnMatrix& x, ColumnMatrix& b) const;
122 
123  T sumOfCol(index_type);
124  T sumOfRow(index_type);
125 
126 
127 
128  /// fast accessors
129  inline T* operator[](index_type r)
130  {
131  return data[r];
132  }
133  inline T const* operator[](index_type r) const
134  {
135  return data[r];
136  }
137 
138  inline T** get_raw_2D_pointer() const
139  {
140  return data;
141  }
142 
143  inline T& operator()(index_type i, index_type j) { return data[i][j]; }
144  inline const T& operator()(index_type i, index_type j) const { return data[i][j]; }
145 
146  /// return false if not invertible.
147  virtual bool invert();
148 
150 
151  /// throws an assertion if not square
152  T determinant();
153 
154  static DenseMatrixGeneric *identity(size_type size);
156  static DenseMatrix *make_diagonal_from_column(const ColumnMatrix& column, size_type rows, size_type cols);
157 
158  virtual void print(std::string&) const;
159 
160  /// Persistent representation...
161  virtual std::string dynamic_type_name() const;
162  virtual void io(Piostream&);
164 
165  /// Friend functions
166  SCISHARE friend void Mult(DenseMatrix&, const DenseMatrix&, const DenseMatrix&);
167 
168 private:
169  void init();
170  T** data;
171  T* dataptr_;
172 };
173 
174 
175 namespace LinearAlgebra
176 {
180 
183 
184  SCISHARE void solve_lapack(const DenseMatrix& matrix, const ColumnMatrix& rhs, ColumnMatrix& lhs);
185 
186  // NOTE: returns 1 if successful, or 0 if unsuccessful (i.e. ignore the solution vector)
187  SCISHARE int solve(const DenseMatrix&, ColumnMatrix&);
188  SCISHARE int solve(const DenseMatrix&, const ColumnMatrix& rhs, ColumnMatrix& lhs);
189  SCISHARE int solve(const DenseMatrix&, std::vector<double>& sol);
190  SCISHARE int solve(const DenseMatrix&, const std::vector<double>& rhs, std::vector<double>& lhs);
191 }
192 
193 
194 SCISHARE void Sub(DenseMatrix&, const DenseMatrix&, const DenseMatrix&);
195 SCISHARE void Add(DenseMatrix&, const DenseMatrix&, const DenseMatrix&);
196 SCISHARE void Add(DenseMatrix&, double, const DenseMatrix&, double, const DenseMatrix&);
197 SCISHARE void Add(double, DenseMatrix&, const DenseMatrix&);
200 SCISHARE void Concat_rows(DenseMatrix&, const DenseMatrix&, const DenseMatrix&); // Added by Saeed Babaeizadeh, Jan. 2006
201 SCISHARE void Concat_cols(DenseMatrix&, const DenseMatrix&, const DenseMatrix&); // Added by Saeed Babaeizadeh, Jan. 2006
202 
203 namespace
204 {
205  Persistent* DenseMatrixGenericMaker()
206  {
207  return new DenseMatrix;
208  }
209 }
210 
211 template <typename T>
212 PersistentTypeID DenseMatrixGeneric<T>::type_id("DenseMatrix", "Matrix", DenseMatrixGenericMaker);
213 
214 template <typename T>
215 int
217 {
218  int sum = 0;
219  sum += SCIRun::compute_checksum(data,this->nrows_);
220  sum += SCIRun::compute_checksum(dataptr_,this->nrows_*this->ncols_);
221  return (sum);
222 }
223 
224 template <typename T>
227 {
228  return new DenseMatrixGeneric(*this);
229 }
230 
231 
232 /// constructors
233 template <typename T>
235 data(0),
236 dataptr_(0)
237 {
238  DEBUG_CONSTRUCTOR("DenseMatrix")
239 }
240 
241 template <typename T>
243 Matrix<T>(r, c)
244 {
245  DEBUG_CONSTRUCTOR("DenseMatrix")
246  init();
247 }
248 
249 template <typename T>
251 Matrix<T>(1, 1)
252 {
253  DEBUG_CONSTRUCTOR("DenseMatrix")
254 
255  init();
256  dataptr_[0] = scalar;
257 }
258 
259 template <typename T>
261 Matrix<double>(1, 3)
262 {
263  DEBUG_CONSTRUCTOR("DenseMatrix")
264 
265  init();
266  dataptr_[0] = vec.x();
267  dataptr_[1] = vec.y();
268  dataptr_[2] = vec.z();
269 }
270 
271 template <typename T>
273 Matrix<T>(1, 3)
274 {
275  DEBUG_CONSTRUCTOR("DenseMatrix")
276 
277  init();
278  dataptr_[0] = pnt.x();
279  dataptr_[1] = pnt.y();
280  dataptr_[2] = pnt.z();
281 }
282 
283 template <typename T>
285 Matrix<T>(1, 6)
286 {
287  DEBUG_CONSTRUCTOR("DenseMatrix")
288 
289  init();
290  dataptr_[0] = tens.xx();
291  dataptr_[1] = tens.xy();
292  dataptr_[2] = tens.xz();
293  dataptr_[3] = tens.yy();
294  dataptr_[4] = tens.yz();
295  dataptr_[5] = tens.zz();
296 }
297 
298 template <typename T>
300 {
301  data = new T*[this->nrows_];
302  T* tmp = new T[this->nrows_ * this->ncols_];
303  dataptr_ = tmp;
304  for (index_type i=0; i < this->nrows_; i++)
305  {
306  data[i] = tmp;
307  tmp += this->ncols_;
308  }
309 }
310 
311 template <typename T>
313 Matrix<T>(m.nrows_, m.ncols_)
314 {
315  DEBUG_CONSTRUCTOR("DenseMatrix")
316 
317  data = new T*[this->nrows_];
318  T* tmp = new T[this->nrows_ * this->ncols_];
319  dataptr_ = tmp;
320  for (index_type i=0; i<static_cast<index_type>(this->nrows_); i++)
321  {
322  data[i] = tmp;
323  T* p = m.data[i];
324  for (int j=0; j<this->ncols_; j++)
325  {
326  *tmp++ = *p++;
327  }
328  }
329 }
330 
331 template <typename T>
333 Matrix<T>(r, c)
334 {
335  DEBUG_CONSTRUCTOR("DenseMatrix")
336  init();
337  std::fill(this->begin(), this->end(), value);
338 }
339 
340 template <typename T>
342 Matrix<T>(4, 4)
343 {
344  DEBUG_CONSTRUCTOR("DenseMatrix")
345 
346  T dummy[16];
347  t.get(dummy);
348  data = new T*[this->nrows_];
349  T* tmp = new T[this->nrows_ * this->ncols_];
350  dataptr_ = tmp;
351  T* p=dummy;
352 
353  for (index_type i=0; i<this->nrows_; i++)
354  {
355  data[i] = tmp;
356  for (index_type j=0; j<this->ncols_; j++)
357  {
358  *tmp++ = static_cast<T>(*p++);
359  }
360  }
361 }
362 
363 template <typename T>
364 T *
366 {
367  return dataptr_;
368 }
369 
370 template <typename T>
371 size_type
373 {
374  return this->nrows() * this->ncols();
375 }
376 
377 template <typename T>
379 {
380  DEBUG_DESTRUCTOR("DenseMatrix")
381 
382  delete[] dataptr_;
383  delete[] data;
384 }
385 
386 
387 /// assignment operator
388 template <typename T>
391 {
392  delete[] dataptr_;
393  delete[] data;
394 
395  this->nrows_ = m.nrows_;
396  this->ncols_ = m.ncols_;
397  data = new T*[this->nrows_];
398  T* tmp = new T[this->nrows_ * this->ncols_];
399  dataptr_ = tmp;
400  for (index_type i=0; i<this->nrows_; i++)
401  {
402  data[i]=tmp;
403  T* p=m.data[i];
404  for (index_type j=0; j<this->ncols_; j++)
405  {
406  *tmp++=*p++;
407  }
408  }
409  return *this;
410 }
411 
412 template <typename T>
413 T
415 {
416  ASSERTRANGE(r, 0, this->nrows_);
417  ASSERTRANGE(c, 0, this->ncols_);
418  return data[r][c];
419 }
420 
421 template <typename T>
422 void
424 {
425  ASSERTRANGE(r, 0, this->nrows_);
426  ASSERTRANGE(c, 0, this->ncols_);
427  data[r][c]=d;
428 }
429 
430 template <typename T>
431 void
433 {
434  ASSERTRANGE(r, 0, this->nrows_);
435  ASSERTRANGE(c, 0, this->ncols_);
436  data[r][c] += d;
437 }
438 
439 template <typename T>
440 T
442 {
443  T min = DBL_MAX;
444  for (index_type k=0; k<this->nrows_*this->ncols_; k++)
445  if (dataptr_[k] < min) min = dataptr_[k];
446  return (min);
447 }
448 
449 template <typename T>
450 T
452 {
453  T max = -DBL_MAX;
454  for (index_type k=0; k<this->nrows_*this->ncols_; k++)
455  if (dataptr_[k] > max) max = dataptr_[k];
456  return (max);
457 }
458 
459 template <typename T>
462 {
463  DenseMatrixGeneric *m=new DenseMatrixGeneric(this->ncols_, this->nrows_);
464  T *mptr = &((*m)[0][0]);
465  for (index_type c=0; c<this->ncols_; c++)
466  for (index_type r=0; r<this->nrows_; r++)
467  *mptr++ = data[r][c];
468  return m;
469 }
470 
471 template <typename T>
473 {
474  ASSERT(this->nrows_ == this->ncols_);
475  for(index_type i=0; i<this->nrows_; i++)
476  {
477  for(index_type j=0; j<this->ncols_; j++)
478  {
479  if (i > j)
480  {
481  std::swap(data[i][j], data[j][i]);
482  }
483  }
484  }
485 }
486 
487 template <typename T>
488 void
490  index_type *&cols, T *&vals)
491 {
492  size = this->ncols_;
493  stride = 1;
494  cols = 0;
495  vals = data[r];
496 }
497 
498 template <typename T>
499 void
501 {
502  std::fill(this->begin(), this->end(), 0);
503 }
504 
505 template <typename T>
506 std::string DenseMatrixGeneric<T>::dynamic_type_name() const { return type_id.type; }
507 
508 template <typename T>
511 {
512  DenseMatrixGeneric *result = zero_matrix(size, size);
513 
514  double* d = result->get_data_pointer();
515  size_type nrows = result->nrows();
516  for (index_type i = 0; i < size; i++)
517  {
518  (*d) = 1.0;
519  d += (nrows+1);
520  }
521 
522  return result;
523 }
524 
525 template <typename T>
528 {
529  DenseMatrixGeneric *result = new DenseMatrixGeneric(rows, cols);
530  result->zero();
531 
532  return result;
533 }
534 
535 template <typename T>
536 void
537 DenseMatrixGeneric<T>::print(std::string& str) const
538 {
539  std::ostringstream oss;
540  for (index_type i=0; i<this->nrows_; i++)
541  {
542  for (index_type j=0; j<this->ncols_; j++)
543  {
544  oss << data[i][j] << " ";
545  }
546  oss << std::endl;
547  }
548  str.assign(oss.str());
549 }
550 
551 template <typename T>
554 {
555  ASSERTRANGE(r1, 0, r2+1);
556  ASSERTRANGE(r2, r1, this->nrows_);
557  ASSERTRANGE(c1, 0, c2+1);
558  ASSERTRANGE(c2, c1, this->ncols_);
559 
560  DenseMatrixGeneric *mat = new DenseMatrixGeneric(r2 - r1 + 1, c2 - c1 + 1);
561  for (index_type i=r1; i <= r2; i++)
562  {
563  memcpy(mat->data[i-r1], data[i] + c1, (c2 - c1 + 1) * sizeof(double));
564  }
565  return mat;
566 }
567 
568 
569 #define DENSEMATRIX_VERSION 4
570 
571 template <typename T>
572 void
574 {
575 
576  int version=stream.begin_class("DenseMatrix", DENSEMATRIX_VERSION);
577  // Do the base class first...
578  Matrix<double>::io(stream);
579 
580  if (version < 4)
581  {
582  int nrows = static_cast<int>(this->nrows_);
583  int ncols = static_cast<int>(this->ncols_);
584  stream.io(nrows);
585  stream.io(ncols);
586  this->nrows_ = static_cast<size_type>(nrows);
587  this->ncols_ = static_cast<size_type>(ncols);
588  }
589  else
590  {
591  long long nrows = static_cast<long long>(this->nrows_);
592  long long ncols = static_cast<long long>(this->ncols_);
593  stream.io(nrows);
594  stream.io(ncols);
595  this->nrows_ = static_cast<size_type>(nrows);
596  this->ncols_ = static_cast<size_type>(ncols);
597  }
598 
599  if(stream.reading())
600  {
601  data=new double*[this->nrows_];
602  double* tmp=new double[this->nrows_ * this->ncols_];
603  dataptr_=tmp;
604  for (index_type i=0; i<this->nrows_; i++)
605  {
606  data[i] = tmp;
607  tmp += this->ncols_;
608  }
609  }
610  stream.begin_cheap_delim();
611 
612  int split;
613  if (stream.reading())
614  {
615  if (version > 2)
616  {
617  split = this->separate_raw_;
618  Pio(stream, split);
619  if (this->separate_raw_)
620  {
621  Pio(stream, this->raw_filename_);
622  FILE *f=fopen(this->raw_filename_.c_str(), "r");
623  if (f)
624  {
625  fread(data[0], sizeof(T), this->nrows_ * this->ncols_, f);
626  fclose(f);
627  }
628  else
629  {
630  const std::string errmsg = "Error reading separated file '" +
631  this->raw_filename_ + "'";
632  std::cerr << errmsg << "\n";
633  SCI_THROW(FileNotFound(errmsg, __FILE__, __LINE__));
634  }
635  }
636  }
637  else
638  {
639  this->separate_raw_ = false;
640  }
641  split = this->separate_raw_;
642  }
643  else
644  { // writing
645  std::string filename = this->raw_filename_;
646  split = this->separate_raw_;
647  if (split)
648  {
649  if (filename == "")
650  {
651  if (stream.file_name.c_str())
652  {
653  size_t pos = stream.file_name.rfind('.');
654  if (pos == std::string::npos) filename = stream.file_name + ".raw";
655  else filename = stream.file_name.substr(0,pos) + ".raw";
656  }
657  else
658  {
659  split=0;
660  }
661  }
662  }
663  Pio(stream, split);
664  if (split)
665  {
666  Pio(stream, filename);
667  FILE *f = fopen(filename.c_str(), "w");
668  fwrite(data[0], sizeof(T), this->nrows_ * this->ncols_, f);
669  fclose(f);
670  }
671  }
672 
673  if (!split)
674  {
675  size_t block_size = this->nrows_ * this->ncols_;
676  if (!stream.block_io(dataptr_, sizeof(T), block_size))
677  {
678  for (size_t i = 0; i < block_size; i++)
679  {
680  stream.io(dataptr_[i]);
681  }
682  }
683  }
684  stream.end_cheap_delim();
685  stream.end_class();
686 }
687 
688 
689 /// @todo: this needs to be refactored
690 template <typename T>
691 bool
693 {
694  if (this->nrows_ != this->ncols_) return false;
695 
696 #if defined(HAVE_LAPACK)
697  // transpose matrix order: Fortran vs C ordering
698 
699  transpose_square_in_place();
700 
701  try
702  {
703  lapackinvert(dataptr_, this->nrows_);
704  }
705  catch (const SCIRun::LapackError& exception)
706  {
707  std::ostringstream oss;
708  oss << "Caught LapackError exception: " << exception.message();
709  // in the absence of a logging service
710  std::cerr << oss.str() << std::endl;
711  return false;
712  }
713 
714  // transpose back to C ordering
715  transpose_square_in_place();
716 
717  return true;
718 #else
719 
720  T** newdata=new T*[this->nrows_];
721  T* tmp=new T[this->nrows_ * this->ncols_];
722  T* newdataptr_=tmp;
723 
724  index_type i;
725  for (i=0; i<this->nrows_; i++)
726  {
727  newdata[i]=tmp;
728  for (index_type j=0; j<this->nrows_; j++)
729  {
730  tmp[j]=0;
731  }
732  tmp[i] = 1;
733  tmp += this->ncols_;
734  }
735 
736  // Gauss-Jordan with partial pivoting
737  for (i=0;i<this->nrows_;i++)
738  {
739  T max=Abs(data[i][i]);
740  index_type row=i;
741  index_type j;
742  for (j=i+1; j<this->nrows_; j++)
743  {
744  if(Abs(data[j][i]) > max)
745  {
746  max=Abs(data[j][i]);
747  row=j;
748  }
749  }
750  if(row != i)
751  {
752  // Switch row pointers for original matrix ...
753  T* tmp=data[i];
754  data[i]=data[row];
755  data[row]=tmp;
756  // ... but switch actual data values for inverse
757  for (j=0; j<this->ncols_; j++)
758  {
759  T ntmp=newdata[i][j];
760  newdata[i][j]=newdata[row][j];
761  newdata[row][j]=ntmp;
762  }
763  }
764  T denom=1./data[i][i];
765  T* r1=data[i];
766  T* n1=newdata[i];
767  for (j=i+1; j<this->nrows_; j++)
768  {
769  T factor=data[j][i]*denom;
770  T* r2=data[j];
771  T* n2=newdata[j];
772  for (index_type k=0;k<this->nrows_;k++)
773  {
774  r2[k]-=factor*r1[k];
775  n2[k]-=factor*n1[k];
776  }
777  }
778  }
779 
780  // Back-substitution
781  for (i=1; i<this->nrows_; i++)
782  {
783  T denom=1./data[i][i];
784  T* r1=data[i];
785  T* n1=newdata[i];
786  for (index_type j=0;j<i;j++)
787  {
788  T factor=data[j][i]*denom;
789  T* r2=data[j];
790  T* n2=newdata[j];
791  for (index_type k=0; k<this->nrows_; k++)
792  {
793  r2[k]-=factor*r1[k];
794  n2[k]-=factor*n1[k];
795  }
796  }
797  }
798 
799  // Normalize
800  for (i=0;i<this->nrows_;i++)
801  {
802  T factor=1./data[i][i];
803  for (index_type j=0;j<this->nrows_; j++)
804  {
805  data[i][j]*=factor;
806  newdata[i][j]*=factor;
807  }
808  }
809 
810  delete[] dataptr_;
811  delete[] data;
812  dataptr_=newdataptr_;
813  data=newdata;
814 
815  // Reorder data back in the right order
816  for (index_type i=0;i<this->nrows_;i++)
817  {
818  T* old_ptr = data[i];
819  T* new_ptr = dataptr_ + i*this->ncols_;
820 
821  T temp;
822  // Swap rows
823  for (index_type j=0; j<this->ncols_;j++)
824  {
825  temp = new_ptr[j];
826  new_ptr[j] = old_ptr[j];
827  old_ptr[j] = temp;
828  }
829 
830  data[i] = new_ptr;
831  }
832 
833  return true;
834 #endif
835 }
836 
837 template <typename T>
838 T
840 {
841  ASSERT(n<this->ncols_);
842  ASSERT(n>=0);
843 
844  T sum = 0;
845 
846  for (index_type i=0; i<this->nrows_; i++)
847  {
848  sum+=data[i][n];
849  }
850 
851  return sum;
852 }
853 
854 template <typename T>
855 T
857 {
858  ASSERT(n < this->nrows_);
859  ASSERT(n >= 0);
860  T* rp = data[n];
861  T sum = 0;
862  index_type i=0;
863  while (i<this->ncols_) sum+=rp[i++];
864  return sum;
865 }
866 
867 template <typename T>
868 T
870 {
871  T a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
872  ASSERTMSG(((this->nrows_ == 4) && (this->ncols_ == 4)),
873  "Number of Rows and Colums for Determinant must equal 4! (Code not completed)");
874  a=data[0][0]; b=data[0][1]; c=data[0][2]; d=data[0][3];
875  e=data[1][0]; f=data[1][1]; g=data[1][2]; h=data[1][3];
876  i=data[2][0]; j=data[2][1]; k=data[2][2]; l=data[2][3];
877  m=data[3][0]; n=data[3][1]; o=data[3][2]; p=data[3][3];
878 
879  T q=a*f*k*p - a*f*l*o - a*j*g*p + a*j*h*o + a*n*g*l - a*n*h*k
880  - e*b*k*p + e*b*l*o + e*j*c*p - e*j*d*o - e*n*c*l + e*n*d*k
881  + i*b*g*p - i*b*h*o - i*f*c*p + i*f*d*o + i*n*c*h - i*n*d*g
882  - m*b*g*l + m*b*h*k + m*f*c*l - m*f*d*k - m*j*c*h + m*j*d*g;
883 
884  return q;
885 }
886 
887 
888 } // End namespace SCIRun
889 
890 #endif
void Sub(ColumnMatrixGeneric< T > &result, const ColumnMatrixGeneric< T > &a, const ColumnMatrixGeneric< T > &b)
Definition: ColumnMatrixFunctions.h:113
virtual void put(index_type r, index_type c, T val)
Definition: DenseMatrix.h:423
virtual bool block_io(void *, size_t, size_t)
Definition: Persistent.h:174
virtual T get(index_type r, index_type c) const
Definition: DenseMatrix.h:414
bool reading() const
Definition: Persistent.h:164
Definition: DenseMatrix.h:68
LockingHandle< Matrix< double > > MatrixHandle
Definition: MatrixFwd.h:55
double xx() const
Definition: Tensor.h:121
virtual DenseMatrixGeneric * make_transpose() const
Definition: DenseMatrix.h:461
double zz() const
Definition: Tensor.h:126
#define SCI_THROW(exc)
Definition: Exception.h:87
virtual ColumnMatrix * column()
Definition: MatrixTypeConverter.h:321
#define ASSERTMSG(condition, message)
Definition: Exception.h:113
static DenseMatrixGeneric * zero_matrix(size_type rows, size_type cols)
Definition: DenseMatrix.h:527
double Abs(double d)
Definition: MiscMath.h:369
Definition: DenseColMajMatrix.h:73
virtual void io(bool &)
Definition: Persistent.cc:193
DenseMatrixGeneric & operator=(const DenseMatrixGeneric &)
assignment operator
Definition: DenseMatrix.h:390
Definition: Persistent.h:89
T * operator[](index_type r)
fast accessors
Definition: DenseMatrix.h:129
double yz() const
Definition: Tensor.h:125
int compute_checksum(T *data, std::size_t length)
Definition: CheckSum.h:38
T const * operator[](index_type r) const
Definition: DenseMatrix.h:133
void y(const double)
Definition: Point.h:135
Definition: Persistent.h:187
Definition: Point.h:49
#define SCISHARE
Definition: share.h:39
double yy() const
Definition: Tensor.h:124
virtual void mult(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseMatrixMultiplication.h:49
void lapackinvert(double *, int)
Definition: sci_lapack.cc:449
T sumOfRow(index_type)
Definition: DenseMatrix.h:856
void get(double *) const
Definition: Transform.cc:584
static DenseMatrix * make_diagonal_from_column(const ColumnMatrix &column, size_type rows, size_type cols)
Definition: DenseMatrixMultiplication.h:215
virtual void begin_cheap_delim()
Definition: Persistent.cc:183
Definition: Matrix.h:104
const T & operator()(index_type i, index_type j) const
Definition: DenseMatrix.h:144
#define ASSERT(condition)
Definition: Assert.h:110
virtual T max()
Definition: DenseMatrix.h:451
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
#define ASSERTRANGE(c, l, h)
Definition: Assert.h:99
Definition: Vector.h:63
T ** get_raw_2D_pointer() const
Definition: DenseMatrix.h:138
void z(const double)
Definition: Point.h:145
size_type ncols_
Definition: Matrix.h:113
Definition: ParallelLinearAlgebraTests.cc:358
double xz() const
Definition: Tensor.h:123
virtual size_type get_data_size() const
Definition: DenseMatrix.h:372
void x(const double)
Definition: Point.h:125
SCISHARE void Concat_rows(DenseMatrix &, const DenseMatrix &, const DenseMatrix &)
Definition: DenseMatrixFunctions.cc:329
Generic exception for internal errors.
long long size_type
Definition: Types.h:40
T * end() const
Definition: Matrix.h:141
T determinant()
throws an assertion if not square
Definition: DenseMatrix.h:869
virtual MatrixHandle submatrix(index_type r1, index_type c1, index_type r2, index_type c2)
Definition: DenseMatrix.h:553
dictionary data
Definition: eabLatVolData.py:11
Definition: ColumnMatrix.h:55
DenseMatrixGeneric()
Constructors.
Definition: DenseMatrix.h:234
size_type nrows_
Definition: Matrix.h:112
void transpose_square_in_place()
Definition: DenseMatrix.h:472
virtual void end_cheap_delim()
Definition: Persistent.cc:188
virtual SparseRowMatrix * sparse()
Definition: MatrixTypeConverter.h:331
Definition: Transform.h:53
SCISHARE void eigenvalues(const DenseMatrix &, ColumnMatrix &, ColumnMatrix &)
Definition: DenseMatrix.cc:461
Definition: Tensor.h:65
LockingHandle< SparseRowMatrix > SparseRowMatrixHandle
Definition: MatrixFwd.h:58
void x(double)
Definition: Vector.h:175
T * begin() const
Definition: Matrix.h:140
virtual void io(Piostream &)
Definition: DenseMatrix.h:573
virtual const char * message() const
Definition: LapackError.cc:59
virtual int compute_checksum()
Definition: DenseMatrix.h:216
SCISHARE void Mult_X_trans(DenseMatrix &, const DenseMatrix &, const DenseMatrix &)
Definition: DenseMatrixFunctions.cc:302
virtual bool invert()
return false if not invertible.
Definition: DenseMatrix.h:692
double xy() const
Definition: Tensor.h:122
virtual void add(index_type r, index_type c, T val)
Definition: DenseMatrix.h:432
virtual DenseMatrixGeneric * clone() const
Public member functions.
Definition: DenseMatrix.h:226
void y(double)
Definition: Vector.h:185
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
virtual void mult_transpose(const ColumnMatrix &x, ColumnMatrix &b, index_type beg=-1, index_type end=-1, int spVec=0) const
Definition: DenseMatrixMultiplication.h:178
static DenseMatrixGeneric * identity(size_type size)
Definition: DenseMatrix.h:510
SCISHARE void svd(const DenseMatrix &, DenseMatrix &, SparseRowMatrixHandle &, DenseMatrix &)
Definition: DenseMatrix.cc:443
virtual ~DenseMatrixGeneric()
Destructor.
Definition: DenseMatrix.h:378
SCISHARE void Concat_cols(DenseMatrix &, const DenseMatrix &, const DenseMatrix &)
Definition: DenseMatrixFunctions.cc:352
virtual T * get_data_pointer() const
Definition: DenseMatrix.h:365
virtual void end_class()
Definition: Persistent.cc:178
T sumOfCol(index_type)
Definition: DenseMatrix.h:839
long long index_type
Definition: Types.h:39
virtual void zero()
slow setters/getter for polymorphic operations
Definition: DenseMatrix.h:500
virtual T min()
Definition: DenseMatrix.h:441
virtual void print(std::string &) const
Definition: DenseMatrix.h:537
virtual std::string dynamic_type_name() const
Persistent representation...
Definition: DenseMatrix.h:506
virtual DenseColMajMatrix * dense_col_maj()
Definition: MatrixTypeConverter.h:299
virtual void io(Piostream &)
Definition: Matrix.cc:58
SCISHARE void Mult_trans_X(DenseMatrix &, const DenseMatrix &, const DenseMatrix &)
Definition: DenseMatrixFunctions.cc:278
virtual void getRowNonzerosNoCopy(index_type r, size_type &size, index_type &stride, index_type *&cols, T *&vals)
Definition: DenseMatrix.h:489
Definition: Persistent.h:64
boost::error_info< struct tag_file_not_found, std::string > FileNotFound
Definition: Exception.h:54
int n
Definition: eab.py:9
SCISHARE int solve(const DenseMatrix &, ColumnMatrix &)
Definition: DenseMatrix.cc:55
std::string file_name
Definition: Persistent.h:135
#define DEBUG_CONSTRUCTOR(type)
Definition: Debug.h:64
static PersistentTypeID type_id
Definition: DenseMatrix.h:163
SCISHARE void eigenvectors(const DenseMatrix &, ColumnMatrix &, ColumnMatrix &, DenseMatrix &)
Definition: DenseMatrix.cc:467
void Add(ColumnMatrixGeneric< T > &result, const ColumnMatrixGeneric< T > &a, const ColumnMatrixGeneric< T > &b)
Definition: ColumnMatrixFunctions.h:209
void z(double)
Definition: Vector.h:195
T & operator()(index_type i, index_type j)
Definition: DenseMatrix.h:143
SCISHARE void solve_lapack(const DenseMatrix &matrix, const ColumnMatrix &rhs, ColumnMatrix &lhs)
Definition: DenseMatrix.cc:437
Definition: LapackError.h:40
DenseMatrixGeneric< double > DenseMatrix
Definition: MatrixFwd.h:44
size_type nrows() const
Definition: Matrix.h:132
Definition: MatrixFwd.h:40
virtual DenseMatrix * dense()
Convert this matrix to the specified type.
Definition: MatrixTypeConverter.h:292
int size
Definition: eabLatVolData.py:2
void multiply(ColumnMatrix &x, ColumnMatrix &b) const
Definition: DenseMatrixMultiplication.h:130
#define DENSEMATRIX_VERSION
Definition: DenseMatrix.h:569
#define DEBUG_DESTRUCTOR(type)
Definition: Debug.h:65
SCISHARE friend void Mult(DenseMatrix &, const DenseMatrix &, const DenseMatrix &)
Friend functions.
Definition: DenseMatrixFunctions.cc:48