CUSP
Loading...
Searching...
No Matches
Input/Output

Provides load and store operations for sparse matrices. More...

Functions

template<typename Printable >
void cusp::print (const Printable &p)
 print a textual representation of an object
 
template<typename Printable , typename Stream >
void cusp::print (const Printable &p, Stream &s)
 Print a textual representation of an object on a given stream.
 
template<typename Matrix >
void cusp::io::read_binary_file (Matrix &mtx, const std::string &filename)
 Read a binary file.
 
template<typename Matrix , typename Stream >
void cusp::io::read_binary_stream (Matrix &mtx, Stream &input)
 Read binary data from a stream.
 
template<typename Matrix >
void cusp::io::write_binary_file (const Matrix &mtx, const std::string &filename)
 Write a binary file.
 
template<typename Matrix , typename Stream >
void cusp::io::write_binary_stream (const Matrix &mtx, Stream &output)
 Write binary data to a stream.
 
template<typename Matrix >
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > cusp::io::read_dimacs_file (Matrix &mtx, const std::string &filename)
 Read a Dimacs file.
 
template<typename Matrix , typename Stream >
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > cusp::io::read_dimacs_stream (Matrix &mtx, Stream &input)
 Read Dimacs data from a stream.
 
template<typename Matrix >
void cusp::io::write_dimacs_file (const Matrix &mtx, const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &t, const std::string &filename)
 Write a Dimacs file.
 
template<typename Matrix , typename Stream >
void cusp::io::write_dimacs_stream (const Matrix &mtx, const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &t, Stream &output)
 Write Dimacs data to a stream.
 
template<typename Matrix >
void cusp::io::read_matrix_market_file (Matrix &mtx, const std::string &filename)
 Read a MatrixMarket file.
 
template<typename Matrix , typename Stream >
void cusp::io::read_matrix_market_stream (Matrix &mtx, Stream &input)
 Read MatrixMarket data from a stream.
 
template<typename Matrix >
void cusp::io::write_matrix_market_file (const Matrix &mtx, const std::string &filename)
 Write a MatrixMarket file.
 
template<typename Matrix , typename Stream >
void cusp::io::write_matrix_market_stream (const Matrix &mtx, Stream &output)
 Write MatrixMarket data to a stream.
 

Detailed Description

Provides load and store operations for sparse matrices.

Provides routines for read/write different file types.

Function Documentation

◆ print() [1/2]

template<typename Printable >
void cusp::print ( const Printable &  p)

print a textual representation of an object

Template Parameters
Printableprintable type
Parameters
pmatrix, array, or other printable object
Example
The following code snippet demonstrates how to use print.
#include <cusp/array2d.h>
#include <cusp/print.h>
int main(void)
{
// initialize a 2x3 matrix
A(0,0) = 10; A(0,1) = 20; A(0,2) = 30;
A(1,0) = 40; A(1,1) = 50; A(1,2) = 60;
// print A
return 0;
}
2D array of elements that may reside in "host" or "device" memory space
The array2d class is a 2D vector container that may contain elements stored in "host" or "device" mem...
Definition array2d.h:94
void print(const Printable &p)
print a textual representation of an object
Print textual representation of an object.

◆ print() [2/2]

template<typename Printable , typename Stream >
void cusp::print ( const Printable &  p,
Stream &  s 
)

Print a textual representation of an object on a given stream.

Template Parameters
Printableprintable type
Streamoutput stream type
Parameters
pmatrix, array, or other printable object
sstream on which to write the output
Example
The following code snippet demonstrates how to use print.
#include <cusp/array2d.h>
#include <cusp/print.h>
#include <sstream>
int main(void)
{
// initialize a 2x3 matrix
A(0,0) = 10; A(0,1) = 20; A(0,2) = 30;
A(1,0) = 40; A(1,1) = 50; A(1,2) = 60;
std::ostringstream oss;
// print A to stream
cusp::print(A, oss);
return 0;
}

◆ read_binary_file()

template<typename Matrix >
void cusp::io::read_binary_file ( Matrix &  mtx,
const std::string &  filename 
)

Read a binary file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
filenamefile name of the binary file
Overview
Note
any contents of mtx will be overwritten
Example
#include <cusp/io/binary.h>
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
return 0;
}
binary file I/O
Coordinate (COO) representation a sparse matrix.
Definition coo_matrix.h:117
Coordinate matrix format.
void read_binary_file(Matrix &mtx, const std::string &filename)
Read a binary file.
See also
write_binary_file
write_binary_stream

◆ read_binary_stream()

template<typename Matrix , typename Stream >
void cusp::io::read_binary_stream ( Matrix &  mtx,
Stream &  input 
)

Read binary data from a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
inputstream from which to read the binary contents
Overview
Note
any contents of mtx will be overwritten
Example
#include <cusp/io/binary.h>
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
return 0;
}
void read_binary_stream(Matrix &mtx, Stream &input)
Read binary data from a stream.
See also
write_binary_file
write_binary_stream

◆ read_dimacs_file()

template<typename Matrix >
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > cusp::io::read_dimacs_file ( Matrix &  mtx,
const std::string &  filename 
)

Read a Dimacs file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
filenamefile name of the Dimacs file
Overview
Note
any contents of mtx will be overwritten
Example
#include <cusp/io/dimacs.h>
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
::cuda::std::tuple<int,int> nodes;
nodes = cusp::io::read_dimacs_file(A, "A.dimacs");
return 0;
}
Dimacs file I/O.
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > read_dimacs_file(Matrix &mtx, const std::string &filename)
Read a Dimacs file.
See also
write_dimacs_file
write_dimacs_stream

◆ read_dimacs_stream()

template<typename Matrix , typename Stream >
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > cusp::io::read_dimacs_stream ( Matrix &  mtx,
Stream &  input 
)

Read Dimacs data from a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
inputstream from which to read the Dimacs contents
Overview
Note
any contents of mtx will be overwritten
Example
#include <cusp/io/dimacs.h>
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
::cuda::std::tuple<int,int> nodes;
nodes = cusp::io::read_dimacs_stream(A, std::cin);
return 0;
}
::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > read_dimacs_stream(Matrix &mtx, Stream &input)
Read Dimacs data from a stream.
See also
write_dimacs_file
write_dimacs_stream

◆ read_matrix_market_file()

template<typename Matrix >
void cusp::io::read_matrix_market_file ( Matrix &  mtx,
const std::string &  filename 
)

Read a MatrixMarket file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
filenamefile name of the MatrixMarket file
Overview
Note
any contents of mtx will be overwritten
Example
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
return 0;
}
void read_matrix_market_file(Matrix &mtx, const std::string &filename)
Read a MatrixMarket file.
MatrixMarket file I/O.
See also
write_matrix_market_file
write_matrix_market_stream

◆ read_matrix_market_stream()

template<typename Matrix , typename Stream >
void cusp::io::read_matrix_market_stream ( Matrix &  mtx,
Stream &  input 
)

Read MatrixMarket data from a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
inputstream from which to read the MatrixMarket contents
Overview
Note
any contents of mtx will be overwritten
Example
int main(void)
{
// read matrix stored in A.mtx into a coo_matrix
return 0;
}
void read_matrix_market_stream(Matrix &mtx, Stream &input)
Read MatrixMarket data from a stream.
See also
write_matrix_market_file
write_matrix_market_stream

◆ write_binary_file()

template<typename Matrix >
void cusp::io::write_binary_file ( const Matrix &  mtx,
const std::string &  filename 
)

Write a binary file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
filenamefile name of the binary file
Overview
Note
if the file already exists it will be overwritten
Example
#include <cusp/array2d.h>
#include <cusp/io/binary.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
// save A into binary file
return 0;
}
void write_binary_file(const Matrix &mtx, const std::string &filename)
Write a binary file.
See also
read_binary_file
read_binary_stream

◆ write_binary_stream()

template<typename Matrix , typename Stream >
void cusp::io::write_binary_stream ( const Matrix &  mtx,
Stream &  output 
)

Write binary data to a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
outputstream to which the binary contents will be written
Example
#include <cusp/array2d.h>
#include <cusp/io/binary.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
// save A into binary file
return 0;
}
void write_binary_stream(const Matrix &mtx, Stream &output)
Write binary data to a stream.
See also
read_binary_file
read_binary_stream

◆ write_dimacs_file()

template<typename Matrix >
void cusp::io::write_dimacs_file ( const Matrix &  mtx,
const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &  t,
const std::string &  filename 
)

Write a Dimacs file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
ta tuple of indices specifying the source and sink vertices
filenamefile name of the Dimacs file
Overview
Note
if the file already exists it will be overwritten
Example
#include <cusp/io/dimacs.h>
#include <cusp/array2d.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
A(3,0) = 0; A(3,1) = 0; A(3,2) = 0; A(3,3) = 0;
// save A into Dimacs file
::cuda::std::tuple<int,int> nodes(0,3);
cusp::io::write_dimacs_file(A, nodes, "A.dimacs");
return 0;
}
void write_dimacs_file(const Matrix &mtx, const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &t, const std::string &filename)
Write a Dimacs file.
See also
read_dimacs_file
read_dimacs_stream

◆ write_dimacs_stream()

template<typename Matrix , typename Stream >
void cusp::io::write_dimacs_stream ( const Matrix &  mtx,
const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &  t,
Stream &  output 
)

Write Dimacs data to a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
ta tuple of indices specifying the source and sink vertices
outputstream to which the Dimacs contents will be written
Example
#include <cusp/io/dimacs.h>
#include <cusp/array2d.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
A(3,0) = 0; A(3,1) = 0; A(3,2) = 0; A(3,3) = 0;
// save A into Dimacs file
::cuda::std::tuple<int,int> nodes(0,3);
cusp::io::write_dimacs_stream(A, nodes, std::cout);
return 0;
}
void write_dimacs_stream(const Matrix &mtx, const ::cuda::std::tuple< typename Matrix::index_type, typename Matrix::index_type > &t, Stream &output)
Write Dimacs data to a stream.
See also
read_dimacs_file
read_dimacs_stream

◆ write_matrix_market_file()

template<typename Matrix >
void cusp::io::write_matrix_market_file ( const Matrix &  mtx,
const std::string &  filename 
)

Write a MatrixMarket file.

Template Parameters
Matrixmatrix container
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
filenamefile name of the MatrixMarket file
Overview
Note
if the file already exists it will be overwritten
Example
#include <cusp/array2d.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
// save A into MatrixMarket file
return 0;
}
void write_matrix_market_file(const Matrix &mtx, const std::string &filename)
Write a MatrixMarket file.
See also
read_matrix_market_file
read_matrix_market_stream

◆ write_matrix_market_stream()

template<typename Matrix , typename Stream >
void cusp::io::write_matrix_market_stream ( const Matrix &  mtx,
Stream &  output 
)

Write MatrixMarket data to a stream.

Template Parameters
Matrixmatrix container
Streamstream type
Parameters
mtxa matrix container (e.g. csr_matrix or coo_matrix)
outputstream to which the MatrixMarket contents will be written
Example
#include <cusp/array2d.h>
int main(void)
{
// create a simple example
A(0,0) = 10; A(0,1) = 0; A(0,2) = 20; A(0,3) = 0;
A(1,0) = 0; A(1,1) = 30; A(1,2) = 0; A(1,3) = 40;
A(2,0) = 50; A(2,1) = 60; A(2,2) = 70; A(2,3) = 80;
// save A into MatrixMarket file
return 0;
}
void write_matrix_market_stream(const Matrix &mtx, Stream &output)
Write MatrixMarket data to a stream.
See also
read_matrix_market_file
read_matrix_market_stream