Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_SerialDenseMatrix.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef _TEUCHOS_SERIALDENSEMATRIX_HPP_
11#define _TEUCHOS_SERIALDENSEMATRIX_HPP_
17#include "Teuchos_BLAS.hpp"
21#include "Teuchos_Assert.hpp"
23#include <cstddef>
24#include <utility>
25
34namespace Teuchos {
35
36template<typename OrdinalType, typename ScalarType>
37class SerialDenseMatrix : public CompObject, public BLAS<OrdinalType, ScalarType>
38{
39public:
40
45
47
48
50
53 SerialDenseMatrix() = default;
54
56
65
67
76
78
84
86
89
91
104
106 virtual ~SerialDenseMatrix();
108
110
111
123
126
128
139
140
142
144
145
147
154
156
162
164
168
170
175
177
181
183 int random();
184
186
188
189
191
198 ScalarType& operator () (OrdinalType rowIndex, OrdinalType colIndex);
199
201
208 const ScalarType& operator () (OrdinalType rowIndex, OrdinalType colIndex) const;
209
211
217
219
224 const ScalarType* operator [] (OrdinalType colIndex) const;
225
227
228 ScalarType* values() const { return values_; }
229
231
233
234
236
240
242
246
248
252
254
258 int scale ( const ScalarType alpha );
259
261
268
270
285
287
299
301
303
304
306
310
312
316
318
320
321
323 OrdinalType numRows() const { return(numRows_); }
324
326 OrdinalType numCols() const { return(numCols_); }
327
329 OrdinalType stride() const { return(stride_); }
330
332 bool empty() const { return(numRows_ == 0 || numCols_ == 0); }
334
336
337
340
343
347
349
350
351 virtual std::ostream& print(std::ostream& os) const;
352
354protected:
359 void deleteArrays();
360 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 ) const;
361
362 static ScalarType*
363 allocateValues(const OrdinalType numRows,
364 const OrdinalType numCols)
365 {
366 const size_t size = size_t(numRows) * size_t(numCols);
367 if (size > 0)
368 return new ScalarType[size];
369 else
370 return nullptr;
371 }
372
373 OrdinalType numRows_ = 0;
374 OrdinalType numCols_ = 0;
375 OrdinalType stride_ = 0;
376 bool valuesCopied_ = false;
377 ScalarType* values_ = nullptr;
378}; // class Teuchos_SerialDenseMatrix
379
380//----------------------------------------------------------------------------------------------------
381// Constructors and Destructor
382//----------------------------------------------------------------------------------------------------
383
384template<typename OrdinalType, typename ScalarType>
387 )
388 : numRows_(numRows_in),
389 numCols_(numCols_in),
390 stride_(numRows_in),
391 valuesCopied_(true),
392 values_(allocateValues(numRows_in, numCols_in))
393{
394 if (zeroOut) {
395 putScalar();
396 }
397}
398
399template<typename OrdinalType, typename ScalarType>
403 )
404 : numRows_(numRows_in),
405 numCols_(numCols_in),
406 stride_(stride_in),
407 valuesCopied_(false),
408 values_(values_in)
409{
410 if(CV == Copy)
411 {
412 stride_ = numRows_;
413 values_ = allocateValues(stride_, numCols_);
414 copyMat(values_in, stride_in, numRows_, numCols_, values_, stride_, 0, 0);
415 valuesCopied_ = true;
416 }
417}
418
419template<typename OrdinalType, typename ScalarType>
421 : CompObject(Source),
422 BLAS<OrdinalType, ScalarType>(Source),
423 valuesCopied_(true)
424{
425 if ( trans == Teuchos::NO_TRANS )
426 {
427 numRows_ = Source.numRows_;
428 numCols_ = Source.numCols_;
429
430 if (!Source.valuesCopied_)
431 {
432 stride_ = Source.stride_;
433 values_ = Source.values_;
434 valuesCopied_ = false;
435 }
436 else
437 {
438 stride_ = numRows_;
439 if(stride_ > 0 && numCols_ > 0) {
440 values_ = allocateValues(stride_, numCols_);
441 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0);
442 }
443 else {
444 numRows_ = 0; numCols_ = 0; stride_ = 0;
445 valuesCopied_ = false;
446 }
447 }
448 }
450 {
451 numRows_ = Source.numCols_;
452 numCols_ = Source.numRows_;
453 stride_ = numRows_;
454 values_ = allocateValues(stride_, numCols_);
455 for (OrdinalType j=0; j<numCols_; j++) {
456 for (OrdinalType i=0; i<numRows_; i++) {
457 values_[j*stride_ + i] = Teuchos::ScalarTraits<ScalarType>::conjugate(Source.values_[i*Source.stride_ + j]);
458 }
459 }
460 }
461 else
462 {
463 numRows_ = Source.numCols_;
464 numCols_ = Source.numRows_;
465 stride_ = numRows_;
466 values_ = allocateValues(stride_, numCols_);
467 for (OrdinalType j=0; j<numCols_; j++) {
468 for (OrdinalType i=0; i<numRows_; i++) {
469 values_[j*stride_ + i] = Source.values_[i*Source.stride_ + j];
470 }
471 }
472 }
473}
474
475
476template<typename OrdinalType, typename ScalarType>
479 )
480 : numRows_(Source.numRows_), numCols_(Source.numCols_), stride_(Source.stride_),
481 valuesCopied_(false), values_(Source.values_)
482{
483 if(CV == Copy)
484 {
485 stride_ = numRows_;
486 values_ = allocateValues(stride_, numCols_);
487 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0);
488 valuesCopied_ = true;
489 }
490}
491
492
493template<typename OrdinalType, typename ScalarType>
498 )
499 : CompObject(), numRows_(numRows_in), numCols_(numCols_in), stride_(Source.stride_),
500 valuesCopied_(false), values_(Source.values_)
501{
502 if(CV == Copy)
503 {
504 stride_ = numRows_in;
505 values_ = allocateValues(stride_, numCols_in);
506 copyMat(Source.values_, Source.stride_, numRows_in, numCols_in, values_, stride_, startRow, startCol);
507 valuesCopied_ = true;
508 }
509 else // CV == View
510 {
511 values_ = values_ + (stride_ * startCol) + startRow;
512 }
513}
514
515template<typename OrdinalType, typename ScalarType>
520
521//----------------------------------------------------------------------------------------------------
522// Shape methods
523//----------------------------------------------------------------------------------------------------
524
525template<typename OrdinalType, typename ScalarType>
528 )
529{
530 deleteArrays(); // Get rid of anything that might be already allocated
531 numRows_ = numRows_in;
532 numCols_ = numCols_in;
533 stride_ = numRows_;
534 values_ = allocateValues(stride_, numCols_);
535 putScalar();
536 valuesCopied_ = true;
537 return(0);
538}
539
540template<typename OrdinalType, typename ScalarType>
543 )
544{
545 deleteArrays(); // Get rid of anything that might be already allocated
546 numRows_ = numRows_in;
547 numCols_ = numCols_in;
548 stride_ = numRows_;
549 values_ = allocateValues(stride_, numCols_);
550 valuesCopied_ = true;
551 return(0);
552}
553
554template<typename OrdinalType, typename ScalarType>
557 )
558{
559 // Allocate space for new matrix
560 ScalarType* values_tmp = allocateValues(numRows_in, numCols_in);
562 for(OrdinalType k = 0; k < numRows_in * numCols_in; k++)
563 {
564 values_tmp[k] = zero;
565 }
566 OrdinalType numRows_tmp = TEUCHOS_MIN(numRows_, numRows_in);
567 OrdinalType numCols_tmp = TEUCHOS_MIN(numCols_, numCols_in);
568 if(values_ != 0)
569 {
570 copyMat(values_, stride_, numRows_tmp, numCols_tmp, values_tmp,
571 numRows_in, 0, 0); // Copy principal submatrix of A to new A
572 }
573 deleteArrays(); // Get rid of anything that might be already allocated
574 numRows_ = numRows_in;
575 numCols_ = numCols_in;
576 stride_ = numRows_;
577 values_ = values_tmp; // Set pointer to new A
578 valuesCopied_ = true;
579 return(0);
580}
581
582//----------------------------------------------------------------------------------------------------
583// Set methods
584//----------------------------------------------------------------------------------------------------
585
586template<typename OrdinalType, typename ScalarType>
588{
589 // Set each value of the dense matrix to "value".
590 for(OrdinalType j = 0; j < numCols_; j++)
591 {
592 for(OrdinalType i = 0; i < numRows_; i++)
593 {
594 values_[i + j*stride_] = value_in;
595 }
596 }
597 return 0;
598}
599
600template<typename OrdinalType, typename ScalarType> void
603{
604 // Notes:
605 // > DefaultBLASImpl::SWAP() uses a deep copy. This fn uses a pointer swap.
606 // > this fn covers both Vector and Matrix, such that some care must be
607 // employed to not swap across types (creating a Vector with non-unitary
608 // numCols_)
609 // > Inherited data that is not currently swapped (since inactive/deprecated):
610 // >> Teuchos::CompObject:
611 // Flops *flopCounter_ [Note: all SerialDenseMatrix ctors initialize a
612 // NULL flop-counter using CompObject(), such that any flop increments
613 // that are computed are not accumulated.]
614 // >> Teuchos::Object: (now removed from inheritance list)
615 // static int tracebackMode (no swap for statics)
616 // std::string label_ (has been reported as a cause of memory overhead)
617
618 std::swap(values_ , B.values_);
619 std::swap(numRows_, B.numRows_);
620 std::swap(numCols_, B.numCols_);
621 std::swap(stride_, B.stride_);
622 std::swap(valuesCopied_, B.valuesCopied_);
623}
624
625template<typename OrdinalType, typename ScalarType>
627{
628 // Set each value of the dense matrix to a random value.
629 for(OrdinalType j = 0; j < numCols_; j++)
630 {
631 for(OrdinalType i = 0; i < numRows_; i++)
632 {
633 values_[i + j*stride_] = ScalarTraits<ScalarType>::random();
634 }
635 }
636 return 0;
637}
638
639template<typename OrdinalType, typename ScalarType>
643 )
644{
645 if(this == &Source)
646 return(*this); // Special case of source same as target
647 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
648 return(*this); // Special case of both are views to same data.
649
650 // If the source is a view then we will return a view, else we will return a copy.
651 if (!Source.valuesCopied_) {
652 if(valuesCopied_) {
653 // Clean up stored data if this was previously a copy.
654 deleteArrays();
655 }
656 numRows_ = Source.numRows_;
657 numCols_ = Source.numCols_;
658 stride_ = Source.stride_;
659 values_ = Source.values_;
660 }
661 else {
662 // If we were a view, we will now be a copy.
663 if(!valuesCopied_) {
664 numRows_ = Source.numRows_;
665 numCols_ = Source.numCols_;
666 stride_ = Source.numRows_;
667 if(stride_ > 0 && numCols_ > 0) {
668 values_ = allocateValues(stride_, numCols_);
669 valuesCopied_ = true;
670 }
671 else {
672 values_ = 0;
673 }
674 }
675 // If we were a copy, we will stay a copy.
676 else {
677 if((Source.numRows_ <= stride_) && (Source.numCols_ == numCols_)) { // we don't need to reallocate
678 numRows_ = Source.numRows_;
679 numCols_ = Source.numCols_;
680 }
681 else { // we need to allocate more space (or less space)
682 deleteArrays();
683 numRows_ = Source.numRows_;
684 numCols_ = Source.numCols_;
685 stride_ = Source.numRows_;
686 if(stride_ > 0 && numCols_ > 0) {
687 values_ = allocateValues(stride_, numCols_);
688 valuesCopied_ = true;
689 }
690 }
691 }
692 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0);
693 }
694 return(*this);
695}
696
697template<typename OrdinalType, typename ScalarType>
699{
700 // Check for compatible dimensions
701 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_))
702 {
703 TEUCHOS_CHK_REF(*this); // Return *this without altering it.
704 }
705 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0, ScalarTraits<ScalarType>::one());
706 return(*this);
707}
708
709template<typename OrdinalType, typename ScalarType>
711{
712 // Check for compatible dimensions
713 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_))
714 {
715 TEUCHOS_CHK_REF(*this); // Return *this without altering it.
716 }
717 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0, -ScalarTraits<ScalarType>::one());
718 return(*this);
719}
720
721template<typename OrdinalType, typename ScalarType>
723 if(this == &Source)
724 return(*this); // Special case of source same as target
725 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
726 return(*this); // Special case of both are views to same data.
727
728 // Check for compatible dimensions
729 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_))
730 {
731 TEUCHOS_CHK_REF(*this); // Return *this without altering it.
732 }
733 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0, 0);
734 return(*this);
735}
736
737//----------------------------------------------------------------------------------------------------
738// Accessor methods
739//----------------------------------------------------------------------------------------------------
740
741template<typename OrdinalType, typename ScalarType>
743{
744#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
745 checkIndex( rowIndex, colIndex );
746#endif
747 return(values_[colIndex * stride_ + rowIndex]);
748}
749
750template<typename OrdinalType, typename ScalarType>
752{
753#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
754 checkIndex( rowIndex, colIndex );
755#endif
756 return(values_[colIndex * stride_ + rowIndex]);
757}
758
759template<typename OrdinalType, typename ScalarType>
761{
762#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
763 checkIndex( 0, colIndex );
764#endif
765 return(values_ + colIndex * stride_);
766}
767
768template<typename OrdinalType, typename ScalarType>
770{
771#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
772 checkIndex( 0, colIndex );
773#endif
774 return(values_ + colIndex * stride_);
775}
776
777//----------------------------------------------------------------------------------------------------
778// Norm methods
779//----------------------------------------------------------------------------------------------------
780
781template<typename OrdinalType, typename ScalarType>
783{
784 OrdinalType i, j;
788 for(j = 0; j < numCols_; j++)
789 {
790 ScalarType sum = 0;
791 ptr = values_ + j * stride_;
792 for(i = 0; i < numRows_; i++)
793 {
795 }
797 if(absSum > anorm)
798 {
799 anorm = absSum;
800 }
801 }
802 // don't compute flop increment unless there is an accumulator
803 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
804 return(anorm);
805}
806
807template<typename OrdinalType, typename ScalarType>
809{
810 OrdinalType i, j;
812
813 for (i = 0; i < numRows_; i++) {
815 for (j=0; j< numCols_; j++) {
816 sum += ScalarTraits<ScalarType>::magnitude(*(values_+i+j*stride_));
817 }
818 anorm = TEUCHOS_MAX( anorm, sum );
819 }
820 // don't compute flop increment unless there is an accumulator
821 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
822 return(anorm);
823}
824
825template<typename OrdinalType, typename ScalarType>
827{
828 OrdinalType i, j;
830 for (j = 0; j < numCols_; j++) {
831 for (i = 0; i < numRows_; i++) {
832 anorm += ScalarTraits<ScalarType>::magnitude(values_[i+j*stride_]*values_[i+j*stride_]);
833 }
834 }
836 // don't compute flop increment unless there is an accumulator
837 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
838 return(anorm);
839}
840
841//----------------------------------------------------------------------------------------------------
842// Comparison methods
843//----------------------------------------------------------------------------------------------------
844
845template<typename OrdinalType, typename ScalarType>
847{
848 bool result = 1;
849 if((numRows_ != Operand.numRows_) || (numCols_ != Operand.numCols_))
850 {
851 result = 0;
852 }
853 else
854 {
855 OrdinalType i, j;
856 for(i = 0; i < numRows_; i++)
857 {
858 for(j = 0; j < numCols_; j++)
859 {
860 if((*this)(i, j) != Operand(i, j))
861 {
862 return 0;
863 }
864 }
865 }
866 }
867 return result;
868}
869
870template<typename OrdinalType, typename ScalarType>
875
876//----------------------------------------------------------------------------------------------------
877// Multiplication method
878//----------------------------------------------------------------------------------------------------
879
880template<typename OrdinalType, typename ScalarType>
886
887template<typename OrdinalType, typename ScalarType>
889{
890 OrdinalType i, j;
892
893 for (j=0; j<numCols_; j++) {
894 ptr = values_ + j*stride_;
895 for (i=0; i<numRows_; i++) { *ptr = alpha * (*ptr); ptr++; }
896 }
897 // don't compute flop increment unless there is an accumulator
898 if (flopCounter_!=0) updateFlops( numRows_*numCols_ );
899 return(0);
900}
901
902template<typename OrdinalType, typename ScalarType>
904{
905 OrdinalType i, j;
907
908 // Check for compatible dimensions
909 if ((numRows_ != A.numRows_) || (numCols_ != A.numCols_))
910 {
911 TEUCHOS_CHK_ERR(-1); // Return error
912 }
913 for (j=0; j<numCols_; j++) {
914 ptr = values_ + j*stride_;
915 for (i=0; i<numRows_; i++) { *ptr = A(i,j) * (*ptr); ptr++; }
916 }
917 // don't compute flop increment unless there is an accumulator
918 if (flopCounter_!=0) updateFlops( numRows_*numCols_ );
919 return(0);
920}
921
922template<typename OrdinalType, typename ScalarType>
924{
925 // Check for compatible dimensions
926 OrdinalType A_nrows = (ETranspChar[transa]!='N') ? A.numCols() : A.numRows();
927 OrdinalType A_ncols = (ETranspChar[transa]!='N') ? A.numRows() : A.numCols();
928 OrdinalType B_nrows = (ETranspChar[transb]!='N') ? B.numCols() : B.numRows();
929 OrdinalType B_ncols = (ETranspChar[transb]!='N') ? B.numRows() : B.numCols();
930 if ((numRows_ != A_nrows) || (A_ncols != B_nrows) || (numCols_ != B_ncols))
931 {
932 TEUCHOS_CHK_ERR(-1); // Return error
933 }
934 // Call GEMM function
935 this->GEMM(transa, transb, numRows_, numCols_, A_ncols, alpha, A.values(), A.stride(), B.values(), B.stride(), beta, values_, stride_);
936
937 // don't compute flop increment unless there is an accumulator
938 if (flopCounter_!=0) {
939 double nflops = 2 * numRows_;
940 nflops *= numCols_;
941 nflops *= A_ncols;
942 updateFlops(nflops);
943 }
944 return(0);
945}
946
947template<typename OrdinalType, typename ScalarType>
949{
950 // Check for compatible dimensions
951 OrdinalType A_nrows = A.numRows(), A_ncols = A.numCols();
952 OrdinalType B_nrows = B.numRows(), B_ncols = B.numCols();
953
954 if (ESideChar[sideA]=='L') {
955 if ((numRows_ != A_nrows) || (A_ncols != B_nrows) || (numCols_ != B_ncols)) {
956 TEUCHOS_CHK_ERR(-1); // Return error
957 }
958 } else {
959 if ((numRows_ != B_nrows) || (B_ncols != A_nrows) || (numCols_ != A_ncols)) {
960 TEUCHOS_CHK_ERR(-1); // Return error
961 }
962 }
963
964 // Call SYMM function
966 this->SYMM(sideA, uplo, numRows_, numCols_, alpha, A.values(), A.stride(), B.values(), B.stride(), beta, values_, stride_);
967
968 // don't compute flop increment unless there is an accumulator
969 if (flopCounter_!=0) {
970 double nflops = 2 * numRows_;
971 nflops *= numCols_;
972 nflops *= A_ncols;
973 updateFlops(nflops);
974 }
975 return(0);
976}
977
978template<typename OrdinalType, typename ScalarType>
979std::ostream& SerialDenseMatrix<OrdinalType, ScalarType>::print(std::ostream& os) const
980{
981 os << std::endl;
982 if(valuesCopied_)
983 os << "Values_copied : yes" << std::endl;
984 else
985 os << "Values_copied : no" << std::endl;
986 os << "Rows : " << numRows_ << std::endl;
987 os << "Columns : " << numCols_ << std::endl;
988 os << "LDA : " << stride_ << std::endl;
989 if(numRows_ == 0 || numCols_ == 0) {
990 os << "(matrix is empty, no values to display)" << std::endl;
991 } else {
992 for(OrdinalType i = 0; i < numRows_; i++) {
993 for(OrdinalType j = 0; j < numCols_; j++){
994 os << (*this)(i,j) << " ";
995 }
996 os << std::endl;
997 }
998 }
999 return os;
1000}
1001
1002//----------------------------------------------------------------------------------------------------
1003// Protected methods
1004//----------------------------------------------------------------------------------------------------
1005
1006template<typename OrdinalType, typename ScalarType>
1008 TEUCHOS_TEST_FOR_EXCEPTION(rowIndex < 0 || rowIndex >= numRows_, std::out_of_range,
1009 "SerialDenseMatrix<T>::checkIndex: "
1010 "Row index " << rowIndex << " out of range [0, "<< numRows_ << ")");
1011 TEUCHOS_TEST_FOR_EXCEPTION(colIndex < 0 || colIndex >= numCols_, std::out_of_range,
1012 "SerialDenseMatrix<T>::checkIndex: "
1013 "Col index " << colIndex << " out of range [0, "<< numCols_ << ")");
1014}
1015
1016template<typename OrdinalType, typename ScalarType>
1017void SerialDenseMatrix<OrdinalType, ScalarType>::deleteArrays(void)
1018{
1019 if (valuesCopied_)
1020 {
1021 delete [] values_;
1022 values_ = 0;
1023 valuesCopied_ = false;
1024 }
1025}
1026
1027template<typename OrdinalType, typename ScalarType>
1028void SerialDenseMatrix<OrdinalType, ScalarType>::copyMat(
1029 ScalarType* inputMatrix, OrdinalType strideInput, OrdinalType numRows_in,
1030 OrdinalType numCols_in, ScalarType* outputMatrix, OrdinalType strideOutput,
1031 OrdinalType startRow, OrdinalType startCol, ScalarType alpha
1032 )
1033{
1034 OrdinalType i, j;
1035 ScalarType* ptr1 = 0;
1036 ScalarType* ptr2 = 0;
1037 for(j = 0; j < numCols_in; j++) {
1038 ptr1 = outputMatrix + (j * strideOutput);
1039 ptr2 = inputMatrix + (j + startCol) * strideInput + startRow;
1041 for(i = 0; i < numRows_in; i++)
1042 {
1043 *ptr1++ += alpha*(*ptr2++);
1044 }
1045 } else {
1046 for(i = 0; i < numRows_in; i++)
1047 {
1048 *ptr1++ = *ptr2++;
1049 }
1050 }
1051 }
1052}
1053
1055template<typename OrdinalType, typename ScalarType>
1063
1065template<typename OrdinalType, typename ScalarType>
1066std::ostream&
1067operator<<(std::ostream &out,
1069{
1070 printer.obj.print(out);
1071 return out;
1072}
1073
1075template<typename OrdinalType, typename ScalarType>
1076SerialDenseMatrixPrinter<OrdinalType,ScalarType>
1081
1082
1083} // namespace Teuchos
1084
1085
1086#endif /* _TEUCHOS_SERIALDENSEMATRIX_HPP_ */
Templated interface class to BLAS routines.
Object for storing data and providing functionality that is common to all computational classes.
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos::DataAccess Mode enumerable type.
Defines basic traits for the scalar field type.
Templated serial, dense, symmetric matrix class.
Templated BLAS wrapper.
Functionality and data that is common to all computational classes.
Smart reference counting pointer class for automatic garbage collection.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
This class creates and provides basic support for dense rectangular matrix of templated type.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
void swap(SerialDenseMatrix< OrdinalType, ScalarType > &B)
Swap values between this matrix and incoming matrix.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
int reshape(OrdinalType numRows, OrdinalType numCols)
Reshaping method for changing the size of a SerialDenseMatrix, keeping the entries.
bool operator!=(const SerialDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
SerialDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool empty() const
Returns whether this matrix is empty.
SerialDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
ScalarType * operator[](OrdinalType colIndex)
Column access method (non-const).
SerialDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
int random()
Set all values in the matrix to be random numbers.
ScalarType scalarType
Typedef for scalar type.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
OrdinalType numRows() const
Returns the row dimension of this matrix.
ScalarType * values() const
Data array access method.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols)
Same as shape() except leaves uninitialized.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
Multiply A * B and add them to this; this = beta * this + alpha*A*B.
bool operator==(const SerialDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
virtual std::ostream & print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
OrdinalType numCols() const
Returns the column dimension of this matrix.
SerialDenseMatrix()=default
Default Constructor.
SerialDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
int shape(OrdinalType numRows, OrdinalType numCols)
Shape method for changing the size of a SerialDenseMatrix, initializing entries to zero.
OrdinalType ordinalType
Typedef for ordinal type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
This structure defines some basic traits for a scalar field type.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
T magnitudeType
Mandatory typedef for result of magnitude.
static T zero()
Returns representation of zero for this scalar type.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
static T random()
Returns a random number (between -one() and +one()) of this scalar type.
Ostream manipulator for SerialDenseMatrix.