COMBINATORIAL_BLAS  1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpMat.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include "SpMat.h"
3 #include "Friends.h"
4 using namespace std;
5 
6 template <class IT, class NT, class DER>
7 SpMat<IT, NT, DER> SpMat<IT, NT, DER>::operator() (const vector<IT> & ri, const vector<IT> & ci) const
8 {
9  if( (!ci.empty()) && (ci.back() > getncol()))
10  {
11  cerr << "Col indices out of bounds" << endl;
12  abort();
13  }
14  if( (!ri.empty()) && (ri.back() > getnrow()))
15  {
16  cerr << "Row indices out of bounds" << endl;
17  abort();
18  }
19 
20  return ((static_cast<DER>(*this)) (ri, ci));
21 }
22 
23 template <class IT, class NT, class DER>
25 {
26  return ((static_cast<DER &>(*this)) == (static_cast<DER &>(rhs)) );
27 }
28 
29 template <class IT, class NT, class DER>
31 {
32  static_cast< DER* >(this)->Split(static_cast< DER & >(partA), static_cast< DER & >(partB));
33 }
34 
35 template <class IT, class NT, class DER>
37 {
38  static_cast< DER* >(this)->Merge(static_cast< DER & >(partA), static_cast< DER & >(partB));
39 }
40 
41 
42 template <class IT, class NT, class DER>
43 template <typename SR>
45  SpMat<IT, NT, DER> & B, bool isAT, bool isBT)
46 {
47  IT A_m, A_n, B_m, B_n;
48 
49  if(isAT)
50  {
51  A_m = A.getncol();
52  A_n = A.getnrow();
53  }
54  else
55  {
56  A_m = A.getnrow();
57  A_n = A.getncol();
58  }
59  if(isBT)
60  {
61  B_m = B.getncol();
62  B_n = B.getnrow();
63  }
64  else
65  {
66  B_m = B.getnrow();
67  B_n = B.getncol();
68  }
69 
70  if(getnrow() == A_m && getncol() == B_n)
71  {
72  if(A_n == B_m)
73  {
74  if(isAT && isBT)
75  {
76  static_cast< DER* >(this)->template PlusEq_AtXBt< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
77  }
78  else if(isAT && (!isBT))
79  {
80  static_cast< DER* >(this)->template PlusEq_AtXBn< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
81  }
82  else if((!isAT) && isBT)
83  {
84  static_cast< DER* >(this)->template PlusEq_AnXBt< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
85  }
86  else
87  {
88  static_cast< DER* >(this)->template PlusEq_AnXBn< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
89  }
90  }
91  else
92  {
93  cerr <<"Not multipliable: " << A_n << "!=" << B_m << endl;
94  }
95  }
96  else
97  {
98  cerr<< "Not addable: "<< getnrow() << "!=" << A_m << " or " << getncol() << "!=" << B_n << endl;
99  }
100 };
101 
102 
103 template<typename SR, typename NUO, typename IU, typename NU1, typename NU2, typename DER1, typename DER2>
105  (const SpMat<IU, NU1, DER1> & A,
106  const SpMat<IU, NU2, DER2> & B,
107  bool isAT, bool isBT,
108  bool clearA = false, bool clearB = false)
109 
110 {
111  IU A_m, A_n, B_m, B_n;
112 
113  if(isAT)
114  {
115  A_m = A.getncol();
116  A_n = A.getnrow();
117  }
118  else
119  {
120  A_m = A.getnrow();
121  A_n = A.getncol();
122  }
123  if(isBT)
124  {
125  B_m = B.getncol();
126  B_n = B.getnrow();
127  }
128  else
129  {
130  B_m = B.getnrow();
131  B_n = B.getncol();
132  }
133 
134  if(A_n == B_m)
135  {
136  if(isAT && isBT)
137  {
138  return Tuples_AtXBt<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
139  }
140  else if(isAT && (!isBT))
141  {
142  return Tuples_AtXBn<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
143  }
144  else if((!isAT) && isBT)
145  {
146  return Tuples_AnXBt<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
147  }
148  else
149  {
150  return Tuples_AnXBn<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
151  }
152  }
153  else
154  {
155  cerr <<"Not multipliable: " << A_n << "!=" << B_m << endl;
156  return new SpTuples<IU, NUO> (0, 0, 0);
157  }
158 }
159 
160 template <class IT, class NT, class DER>
161 inline ofstream& SpMat<IT, NT, DER>::put(ofstream& outfile) const
162 {
163  return static_cast<const DER*>(this)->put(outfile);
164 }
165 
166 template <class IT, class NT, class DER>
167 inline ifstream& SpMat<IT, NT, DER>::get(ifstream& infile)
168 {
169  cout << "Getting... SpMat" << endl;
170  return static_cast<DER*>(this)->get(infile);
171 }
172 
173 
174 template < typename UIT, typename UNT, typename UDER >
175 ofstream& operator<<(ofstream& outfile, const SpMat< UIT,UNT,UDER > & s)
176 {
177  return s.put(outfile);
178 }
179 
180 template < typename UIT, typename UNT, typename UDER >
181 ifstream& operator>> (ifstream& infile, SpMat< UIT,UNT,UDER > & s)
182 {
183  return s.get(infile);
184 }
185