COMBINATORIAL_BLAS  1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpMat.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* Parallel Combinatorial BLAS Library (for Graph Computations) */
3 /* version 1.2 -------------------------------------------------*/
4 /* date: 10/06/2011 --------------------------------------------*/
5 /* authors: Aydin Buluc (abuluc@lbl.gov), Adam Lugowski --------*/
6 /****************************************************************/
7 /*
8 Copyright (c) 2011, Aydin Buluc
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27 */
28 
29 #ifndef _SP_MAT_H
30 #define _SP_MAT_H
31 
32 #include <iostream>
33 #include <vector>
34 #include <utility>
35 #include "CombBLAS.h"
36 #include "SpDefs.h"
37 #include "promote.h"
38 #include "LocArr.h"
39 
40 
41 // Forward declaration (required since a friend function returns a SpTuples object)
42 template <class IU, class NU>
43 class SpTuples;
44 
45 
52 template < class IT, class NT, class DER >
53 class SpMat
54 {
55 public:
59  void Create(const vector<IT> & essentials)
60  {
61  static_cast<DER*>(this)->CreateImpl(essentials);
62  }
63 
64  void Create(IT size, IT nRow, IT nCol, tuple<IT, IT, NT> * mytuples)
65  {
66  static_cast<DER*>(this)->CreateImpl(size, nRow, nCol, mytuples);
67  }
68 
69  SpMat< IT,NT,DER > operator() (const vector<IT> & ri, const vector<IT> & ci) const;
70 
71  template <typename SR>
72  void SpGEMM( SpMat< IT,NT,DER > & A, SpMat< IT,NT,DER > & B, bool isAT, bool isBT);
73 
74  // ABAB: A semiring elementwise operation with automatic type promotion is required for completeness (should cover +/- and .* ?)
75  // ABAB: A neat version of ConvertNumericType should be in base class (an operator SpMat<NIT,NNT,NDER>())
76 
77  void Split( SpMat< IT,NT,DER > & partA, SpMat< IT,NT,DER > & partB);
78  void Merge( SpMat< IT,NT,DER > & partA, SpMat< IT,NT,DER > & partB);
79 
81  {
82  return static_cast<const DER*>(this)->GetArrays();
83  }
84  vector<IT> GetEssentials() const
85  {
86  return static_cast<const DER*>(this)->GetEssentials();
87  }
88 
89  void Transpose()
90  {
91  static_cast<DER*>(this)->Transpose();
92  }
93 
94  bool operator== (const SpMat< IT,NT,DER > & rhs) const;
95 
96  ofstream& put(ofstream& outfile) const;
97  ifstream& get(ifstream& infile);
98 
99  bool isZero() const { return static_cast<const DER*>(this)->isZero(); }
100  IT getnrow() const { return static_cast<const DER*>(this)->getnrow(); }
101  IT getncol() const { return static_cast<const DER*>(this)->getncol(); }
102  IT getnnz() const { return static_cast<const DER*>(this)->getnnz(); }
103 
104 protected:
105 
106  template < typename UIT, typename UNT, typename UDER >
107  friend ofstream& operator<< (ofstream& outfile, const SpMat< UIT,UNT,UDER > & s);
108 
109  template < typename UIT, typename UNT, typename UDER >
110  friend ifstream& operator>> (ifstream& infile, SpMat< UIT,UNT,UDER > & s);
111 
114  template< class SR, class NUO, class IU, class NU1, class NU2, class DER1, class DER2 >
115  friend SpTuples< IU, NUO > *
116  MultiplyReturnTuples (const SpMat< IU, NU1, DER1 > & A, const SpMat< IU, NU2, DER2 > & B, bool isAT, bool isBT, bool clearA, bool clearB);
117 
118 };
119 
120 #include "SpMat.cpp"
121 #endif
122