COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
SpMat.cpp
Go to the documentation of this file.
1/****************************************************************/
2/* Parallel Combinatorial BLAS Library (for Graph Computations) */
3/* version 1.6 -------------------------------------------------*/
4/* date: 6/15/2017 ---------------------------------------------*/
5/* authors: Ariful Azad, Aydin Buluc --------------------------*/
6/****************************************************************/
7/*
8 Copyright (c) 2010-2017, The Regents of the University of California
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
30#include <cstdlib>
31#include "SpMat.h"
32#include "Friends.h"
33
34namespace combblas {
35
36template <class IT, class NT, class DER>
37SpMat<IT, NT, DER> SpMat<IT, NT, DER>::operator() (const std::vector<IT> & ri, const std::vector<IT> & ci) const
38{
39 if( (!ci.empty()) && (ci.back() > getncol()))
40 {
41 std::cerr << "Col indices out of bounds" << std::endl;
42 abort();
43 }
44 if( (!ri.empty()) && (ri.back() > getnrow()))
45 {
46 std::cerr << "Row indices out of bounds" << std::endl;
47 abort();
48 }
49
50 return ((static_cast<DER>(*this)) (ri, ci));
51}
52
53template <class IT, class NT, class DER>
54bool SpMat<IT, NT, DER>::operator== (const SpMat<IT, NT, DER> & rhs) const
55{
56 return ((static_cast<DER &>(*this)) == (static_cast<DER &>(rhs)) );
57}
58
59template <class IT, class NT, class DER>
60void SpMat<IT, NT, DER>::Split( SpMat< IT,NT,DER > & partA, SpMat< IT,NT,DER > & partB)
61{
62 static_cast< DER* >(this)->Split(static_cast< DER & >(partA), static_cast< DER & >(partB));
63}
64
65template <class IT, class NT, class DER>
66void SpMat<IT, NT, DER>::Merge( SpMat< IT,NT,DER > & partA, SpMat< IT,NT,DER > & partB)
67{
68 static_cast< DER* >(this)->Merge(static_cast< DER & >(partA), static_cast< DER & >(partB));
69}
70
71
72template <class IT, class NT, class DER>
73template <typename SR>
74void SpMat<IT, NT, DER>::SpGEMM(SpMat<IT, NT, DER> & A,
75 SpMat<IT, NT, DER> & B, bool isAT, bool isBT)
76{
77 IT A_m, A_n, B_m, B_n;
78
79 if(isAT)
80 {
81 A_m = A.getncol();
82 A_n = A.getnrow();
83 }
84 else
85 {
86 A_m = A.getnrow();
87 A_n = A.getncol();
88 }
89 if(isBT)
90 {
91 B_m = B.getncol();
92 B_n = B.getnrow();
93 }
94 else
95 {
96 B_m = B.getnrow();
97 B_n = B.getncol();
98 }
99
100 if(getnrow() == A_m && getncol() == B_n)
101 {
102 if(A_n == B_m)
103 {
104 if(isAT && isBT)
105 {
106 static_cast< DER* >(this)->template PlusEq_AtXBt< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
107 }
108 else if(isAT && (!isBT))
109 {
110 static_cast< DER* >(this)->template PlusEq_AtXBn< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
111 }
112 else if((!isAT) && isBT)
113 {
114 static_cast< DER* >(this)->template PlusEq_AnXBt< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
115 }
116 else
117 {
118 static_cast< DER* >(this)->template PlusEq_AnXBn< SR >(static_cast< DER & >(A), static_cast< DER & >(B));
119 }
120 }
121 else
122 {
123 std::cerr <<"Not multipliable: " << A_n << "!=" << B_m << std::endl;
124 }
125 }
126 else
127 {
128 std::cerr<< "Not addable: "<< getnrow() << "!=" << A_m << " or " << getncol() << "!=" << B_n << std::endl;
129 }
130};
131
132
133template<typename SR, typename NUO, typename IU, typename NU1, typename NU2, typename DER1, typename DER2>
134SpTuples<IU, NUO> * MultiplyReturnTuples
135 (const SpMat<IU, NU1, DER1> & A,
136 const SpMat<IU, NU2, DER2> & B,
137 bool isAT, bool isBT,
138 bool clearA = false, bool clearB = false)
139
140{
141 IU A_n, B_m;
142
143 if(isAT)
144 {
145 A_n = A.getnrow();
146 }
147 else
148 {
149 A_n = A.getncol();
150 }
151 if(isBT)
152 {
153 B_m = B.getncol();
154 }
155 else
156 {
157 B_m = B.getnrow();
158 }
159
160 if(A_n == B_m)
161 {
162 if(isAT && isBT)
163 {
164 return Tuples_AtXBt<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
165 }
166 else if(isAT && (!isBT))
167 {
168 return Tuples_AtXBn<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
169 }
170 else if((!isAT) && isBT)
171 {
172 return Tuples_AnXBt<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
173 }
174 else
175 {
176 return Tuples_AnXBn<SR, NUO>(static_cast< const DER1 & >(A), static_cast< const DER2 & >(B), clearA, clearB);
177 }
178 }
179 else
180 {
181 std::cerr <<"Not multipliable: " << A_n << "!=" << B_m << std::endl;
182 return new SpTuples<IU, NUO> (0, 0, 0);
183 }
184}
185
186template <class IT, class NT, class DER>
187inline std::ofstream& SpMat<IT, NT, DER>::put(std::ofstream& outfile) const
188{
189 return static_cast<const DER*>(this)->put(outfile);
190}
191
192template <class IT, class NT, class DER>
193inline std::ifstream& SpMat<IT, NT, DER>::get(std::ifstream& infile)
194{
195 std::cout << "Getting... SpMat" << std::endl;
196 return static_cast<DER*>(this)->get(infile);
197}
198
199
200template < typename UIT, typename UNT, typename UDER >
201std::ofstream& operator<<(std::ofstream& outfile, const SpMat< UIT,UNT,UDER > & s)
202{
203 return s.put(outfile);
204}
205
206template < typename UIT, typename UNT, typename UDER >
207std::ifstream& operator>> (std::ifstream& infile, SpMat< UIT,UNT,UDER > & s)
208{
209 return s.get(infile);
210}
211
212}
int64_t IT
Definition test.cpp:53
bool operator==(const SpMat< IT, NT, DER > &rhs) const
Definition SpMat.cpp:54
SpMat< IT, NT, DER > operator()(const std::vector< IT > &ri, const std::vector< IT > &ci) const
Definition SpMat.cpp:37
std::ofstream & put(std::ofstream &outfile) const
Definition SpMat.cpp:187
void Merge(SpMat< IT, NT, DER > &partA, SpMat< IT, NT, DER > &partB)
Definition SpMat.cpp:66
void Split(SpMat< IT, NT, DER > &partA, SpMat< IT, NT, DER > &partB)
Definition SpMat.cpp:60
void SpGEMM(SpMat< IT, NT, DER > &A, SpMat< IT, NT, DER > &B, bool isAT, bool isBT)
Definition SpMat.cpp:74
std::ifstream & get(std::ifstream &infile)
Definition SpMat.cpp:193
std::ofstream & operator<<(std::ofstream &outfile, const SpMat< UIT, UNT, UDER > &s)
Definition SpMat.cpp:201
std::ifstream & operator>>(std::ifstream &infile, SpMat< UIT, UNT, UDER > &s)
Definition SpMat.cpp:207
SpTuples< IU, NUO > * MultiplyReturnTuples(const SpMat< IU, NU1, DER1 > &A, const SpMat< IU, NU2, DER2 > &B, bool isAT, bool isBT, bool clearA=false, bool clearB=false)
Definition SpMat.cpp:135
double A