45template <
class IU,
class NU>
48template <
class IU,
class NU>
51template <
class IU,
class NU>
54template <
class IU,
class NU>
64template <
class IT,
class NT>
65class SpTuples:
public SpMat<IT, NT, SpTuples<IT,NT> >
89 template <
typename BINFUNC>
115 std::vector<bool> existing(n,
false);
117 for(
IT i=0; i< nnz; ++i)
119 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i]))
122 existing[joker::get<0>(
tuples[i])] =
true;
124 joker::get<2>(
tuples[i]) = loopval;
127 std::vector<IT> missingindices;
128 for(
IT i = 0; i < n; ++i)
130 if(!existing[i]) missingindices.push_back(i);
133 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz+toadd];
140 for(
IT i=0; i< toadd; ++i)
142 ntuples[nnz+i] = std::make_tuple(missingindices[i], missingindices[i], loopval);
145 ::operator
delete(
tuples);
149 isOperatorNew =
false;
160 IT AddLoops(std::vector<NT> loopvals,
bool replaceExisting=
false)
164 std::vector<bool> existing(n,
false);
166 for(
IT i=0; i< nnz; ++i)
168 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i]))
171 existing[joker::get<0>(
tuples[i])] =
true;
173 joker::get<2>(
tuples[i]) = loopvals[joker::get<0>(
tuples[i])];
176 std::vector<IT> missingindices;
177 for(
IT i = 0; i < n; ++i)
179 if(!existing[i]) missingindices.push_back(i);
182 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz+toadd];
186 for(
IT i=0; i< toadd; ++i)
188 ntuples[nnz+i] = std::make_tuple(missingindices[i], missingindices[i], loopvals[missingindices[i]]);
191 ::operator
delete(
tuples);
195 isOperatorNew =
false;
206 for(
IT i=0; i< nnz; ++i)
208 if(joker::get<0>(
tuples[i]) == joker::get<1>(
tuples[i])) ++loop;
210 std::tuple<IT, IT, NT> * ntuples =
new std::tuple<IT,IT,NT>[nnz-loop];
213 for(
IT i=0; i< nnz; ++i)
215 if(joker::get<0>(
tuples[i]) != joker::get<1>(
tuples[i]))
217 ntuples[ni++] =
tuples[i];
221 ::operator
delete(
tuples);
225 isOperatorNew =
false;
235 std::tuple<IT,IT,NT> * maxit = std::max_element(
tuples,
tuples+nnz, rowcmp);
236 std::tuple<IT,IT,NT> * minit = std::min_element(
tuples,
tuples+nnz, rowcmp);
237 return std::make_pair(joker::get<0>(*minit), joker::get<0>(*maxit));
240 return std::make_pair(0,0);
247 std::tuple<IT,IT,NT> * maxit = std::max_element(
tuples,
tuples+nnz, colcmp);
248 std::tuple<IT,IT,NT> * minit = std::min_element(
tuples,
tuples+nnz, colcmp);
249 return std::make_pair(joker::get<1>(*minit), joker::get<1>(*maxit));
252 return std::make_pair(0,0);
258 template<
typename SR,
typename IU,
typename NU>
261 template<
typename SR,
typename IU,
typename NU>
264 std::ofstream&
putstream (std::ofstream& outfile)
const;
265 std::ofstream&
put (std::ofstream& outfile)
const
269 std::ifstream&
get (std::ifstream& infile) {
return getstream(infile); }
272 bool isZero()
const {
return (nnz == 0); }
278 std::tuple<IT, IT, NT> *
tuples;
292 template <
class IU,
class NU>
295 template <
class IU,
class NU>
static bool is_sorted(_ForwardIterator __first, _ForwardIterator __last)
std::ifstream & get(std::ifstream &infile)
std::ofstream & put(std::ofstream &outfile) const
std::tuple< IT, IT, NT > * tuples
SpTuples(const SpTuples< IT, NT > &rhs)
SpTuples(const SpDCCols< IT, NT > &rhs)
SpTuples< IT, NT > & operator=(const SpTuples< IT, NT > &rhs)
SpTuples(int64_t size, IT nRow, IT nCol)
IT AddLoops(NT loopval, bool replaceExisting=false)
SpTuples(int64_t size, IT nRow, IT nCol, StackEntry< NT, std::pair< IT, IT > > *&multstack)
friend SpTuples< IU, NU > MergeAll(const std::vector< SpTuples< IU, NU > * > &ArrSpTups, IU mstar, IU nstar, bool delarrs)
SpTuples(int64_t maxnnz, IT nRow, IT nCol, std::vector< IT > &edges, bool removeloops=true)
std::ofstream & putstream(std::ofstream &outfile) const
std::ifstream & getstream(std::ifstream &infile)
IT AddLoops(std::vector< NT > loopvals, bool replaceExisting=false)
void RemoveDuplicates(BINFUNC BinOp)
SpTuples(int64_t size, IT nRow, IT nCol, std::tuple< IT, IT, NT > *mytuples, bool sorted=false, bool isOpNew=false)
SpTuples(const SpCCols< IT, NT > &rhs)
std::tuple< IT, IT, NT > back()
std::pair< IT, IT > ColLimits()
friend SpTuples< IU, NU > * MergeAllRec(const std::vector< SpTuples< IU, NU > * > &ArrSpTups, IU mstar, IU nstar)
std::tuple< IT, IT, NT > front()
std::pair< IT, IT > RowLimits()