51 template<
typename T >
66 TRIPLET_META_TYPE meta;
70 ULI
i()
const {
return row; }
79 void setPosition(
const unsigned long int i,
const unsigned long int j ) {
123 static std::vector< Triplet< T > >
load(
const std::string fn, ULI &m, ULI &n ) {
124 std::fstream file( fn.c_str(), std::ios::in | std::ios::binary );
125 ULI
i; ULI
j;
double v;
126 std::vector< Triplet< T > > ret;
127 if( !file.is_open() ) {
128 std::cerr <<
"Error while opening file" << std::endl;
131 file.read( (
char*) &i,
sizeof( ULI ) );
132 file.read( (
char*) &j,
sizeof( ULI ) );
136 std::cout <<
"m: " << m <<
", n: " << n << std::endl;
139 file.read( (
char*) &i,
sizeof( ULI ) );
141 file.read( (
char*) &j,
sizeof( ULI ) );
142 file.read( (
char*) &v,
sizeof( T ) );
144 std::cout <<
"Pushed back: ( " << i <<
" , " << j <<
" , " << v <<
" )" << std::endl;
160 static std::vector< Triplet< T > >
loadCRS(
const std::string fn, ULI &m, ULI &n ) {
161 std::fstream file( fn.c_str(), std::ios::in );
163 if ( !file.is_open() ) {
164 std::cerr <<
"Error while opening file" << std::endl;
173 std::vector< ULI > row_start( m+1 );
174 for(
size_t i = 0;
i < m+1; ++
i )
175 file >> row_start[
i ];
177 std::vector< ULI > cols( nonzeroes );
178 for(
size_t j = 0;
j < nonzeroes; ++
j )
183 std::vector< Triplet< T > > ret;
185 for(
size_t k = 0; k < nonzeroes; ++k ) {
186 while( k == row_start[ currow + 1 ] ) {
188 if( currow > m + 1 ) {
189 std::cerr <<
"Error in CRS file" << std::endl;
194 ret.push_back(
Triplet< T >( currow, cols[ k ], curval ) );
210 static void save( std::string fn,
Triplet< T >* toWrite,
const ULI m,
const ULI n,
const ULI s ) {
211 std::fstream myFile ( fn.c_str(), std::ios::out | std::ios::binary);
212 myFile.write( (
char*) &m,
sizeof( ULI ) );
213 myFile.write( (
char*) &n,
sizeof( ULI ) );
214 for(
unsigned long int i = 0;
i<s;
i++ ) {
215 const ULI wi = toWrite[
i ].
i();
216 const ULI wj = toWrite[
i ].
j();
217 const double wv = toWrite[
i ].
value;
219 std::cout <<
"Wrote: ( " << wi <<
" , " << wj <<
" , " << wv <<
" ) " << std::endl;
221 myFile.write( (
char*) &( wi ),
sizeof( ULI ) );
222 myFile.write( (
char*) &( wj ),
sizeof( ULI ) );
223 myFile.write( (
char*) &( wv ),
sizeof( T ) );
238 static void save( std::string fn, std::vector<
Triplet< T > > &toWrite,
const ULI m,
const ULI n ) {
239 save( fn, &( toWrite[ 0 ] ), m, n, toWrite.size() );
static std::vector< Triplet< T > > load(const std::string fn, ULI &m, ULI &n)
Loads an array of triplets from a binary file.
Definition: Triplet.hpp:123
void setRowPosition(const unsigned long int i)
Set the row coordinate of this nonzero.
Definition: Triplet.hpp:85
static void save(std::string fn, Triplet< T > *toWrite, const ULI m, const ULI n, const ULI s)
Saves an array of triplets to a file, in binary format.
Definition: Triplet.hpp:210
Triplet()
Base constructor.
Definition: Triplet.hpp:107
void setPosition(const unsigned long int i, const unsigned long int j)
Set the coordinates of this nonzero.
Definition: Triplet.hpp:79
ULI row
The row coordinate of this triplet.
Definition: Triplet.hpp:57
ULI i() const
Definition: Triplet.hpp:70
Triplet(const Triplet< T > &toCopy)
Copy constructor.
Definition: Triplet.hpp:110
Triplet(ULI ii, ULI ij, T val)
Base constructor.
Definition: Triplet.hpp:104
static void save(std::string fn, std::vector< Triplet< T > > &toWrite, const ULI m, const ULI n)
Saves a std::vector of triplets to a file, in binary format.
Definition: Triplet.hpp:238
ULI column
The column coordinate of this triplet.
Definition: Triplet.hpp:60
void transpose()
Transposes this triplet, i.e., swapping the row and column value.
Definition: Triplet.hpp:229
T value
Value stored at this triplet.
Definition: Triplet.hpp:95
static std::vector< Triplet< T > > loadCRS(const std::string fn, ULI &m, ULI &n)
Loads a CRS text file and transforms it into a vector of Triplets.
Definition: Triplet.hpp:160
void rowOffset(ULI offset)
Subtracts a given value from this nonzero row index.
Definition: Triplet.hpp:76
ULI j() const
Definition: Triplet.hpp:73
A single triplet value.
Definition: Triplet.hpp:52
void setColumnPosition(const unsigned long int j)
Set the column coordinate of this nonzero.
Definition: Triplet.hpp:90