45 template <
class IU,
class NU>
48 template <
class IU,
class NU>
59 template <
class IT,
class NT>
60 class SpTuples:
public SpMat<IT, NT, SpTuples<IT,NT> >
65 SpTuples (
int64_t size, IT nRow, IT nCol, std::tuple<IT, IT, NT> * mytuples,
bool sorted =
false,
bool isOpNew =
false);
66 SpTuples (
int64_t maxnnz, IT nRow, IT nCol, std::vector<IT> & edges,
bool removeloops =
true);
68 SpTuples (
const SpTuples<IT,NT> & rhs);
69 SpTuples (
const SpDCCols<IT,NT> & rhs);
72 SpTuples<IT,NT> &
operator=(
const SpTuples<IT,NT> & rhs);
83 template <
typename BINFUNC>
107 IT
AddLoops(NT loopval,
bool replaceExisting=
false)
109 std::vector<bool> existing(n,
false);
111 for(IT i=0; i< nnz; ++i)
113 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i]))
116 existing[joker::get<0>(
tuples[i])] =
true;
118 joker::get<2>(
tuples[i]) = loopval;
121 std::vector<IT> missingindices;
122 for(IT i = 0; i < n; ++i)
124 if(!existing[i]) missingindices.push_back(i);
127 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz+toadd];
134 for(IT i=0; i< toadd; ++i)
136 ntuples[nnz+i] = std::make_tuple(missingindices[i], missingindices[i], loopval);
139 ::operator
delete(
tuples);
143 isOperatorNew =
false;
154 IT
AddLoops(std::vector<NT> loopvals,
bool replaceExisting=
false)
158 std::vector<bool> existing(n,
false);
160 for(IT i=0; i< nnz; ++i)
162 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i]))
165 existing[joker::get<0>(
tuples[i])] =
true;
167 joker::get<2>(
tuples[i]) = loopvals[joker::get<0>(
tuples[i])];
170 std::vector<IT> missingindices;
171 for(IT i = 0; i < n; ++i)
173 if(!existing[i]) missingindices.push_back(i);
176 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz+toadd];
180 for(IT i=0; i< toadd; ++i)
182 ntuples[nnz+i] = std::make_tuple(missingindices[i], missingindices[i], loopvals[missingindices[i]]);
185 ::operator
delete(
tuples);
189 isOperatorNew =
false;
200 for(IT i=0; i< nnz; ++i)
202 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i])) ++loop;
204 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz-loop];
207 for(IT i=0; i< nnz; ++i)
209 if(joker::get<0>(
tuples[i]) != joker::get<1>(
tuples[i]))
211 ntuples[ni++] =
tuples[i];
215 ::operator
delete(
tuples);
219 isOperatorNew =
false;
229 std::tuple<IT,IT,NT> * maxit = std::max_element(
tuples,
tuples+nnz, rowcmp);
230 std::tuple<IT,IT,NT> * minit = std::min_element(
tuples,
tuples+nnz, rowcmp);
231 return std::make_pair(joker::get<0>(*minit), joker::get<0>(*maxit));
234 return std::make_pair(0,0);
241 std::tuple<IT,IT,NT> * maxit = std::max_element(
tuples,
tuples+nnz, colcmp);
242 std::tuple<IT,IT,NT> * minit = std::min_element(
tuples,
tuples+nnz, colcmp);
243 return std::make_pair(joker::get<1>(*minit), joker::get<1>(*maxit));
246 return std::make_pair(0,0);
252 template<
typename SR,
typename IU,
typename NU>
255 template<
typename SR,
typename IU,
typename NU>
258 std::ofstream&
putstream (std::ofstream& outfile)
const;
259 std::ofstream&
put (std::ofstream& outfile)
const 262 std::ifstream&
getstream (std::ifstream& infile);
263 std::ifstream&
get (std::ifstream& infile) {
return getstream(infile); }
266 bool isZero()
const {
return (nnz == 0); }
285 template <
class IU,
class NU>
288 template <
class IU,
class NU>
std::tuple< IT, IT, NT > * tuples
static bool is_sorted(_ForwardIterator __first, _ForwardIterator __last)
friend SpTuples< IU, NU > MergeAll(const std::vector< SpTuples< IU, NU > *> &ArrSpTups, IU mstar, IU nstar, bool delarrs)
IT AddLoops(NT loopval, bool replaceExisting=false)
void RemoveDuplicates(BINFUNC BinOp)
IT AddLoops(std::vector< NT > loopvals, bool replaceExisting=false)
std::tuple< IT, IT, NT > back()
friend SpTuples< IU, NU > * MergeAllRec(const std::vector< SpTuples< IU, NU > *> &ArrSpTups, IU mstar, IU nstar)
std::pair< IT, IT > ColLimits()
SpTuples(int64_t size, IT nRow, IT nCol)
std::pair< IT, IT > RowLimits()
std::ofstream & putstream(std::ofstream &outfile) const
std::tuple< IT, IT, NT > front()
std::ifstream & getstream(std::ifstream &infile)
std::ofstream & put(std::ofstream &outfile) const
SpTuples< IT, NT > & operator=(const SpTuples< IT, NT > &rhs)