20#ifndef CCGSL_SPMATRIX_HPP
21#define CCGSL_SPMATRIX_HPP
24#include<gsl/gsl_spmatrix.h>
45 COO = GSL_SPMATRIX_COO,
47 CSC = GSL_SPMATRIX_CSC,
49 CSR = GSL_SPMATRIX_CSR,
53 CCS = GSL_SPMATRIX_CCS,
55 CRS = GSL_SPMATRIX_CRS
71 explicit spmatrix(
size_t const n1,
size_t const n2 ){
72 if( n1 > 0 and n2 > 0 )
ccgsl_pointer = gsl_spmatrix_alloc( n1, n2 );
76 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
93 if( n1 > 0 and n2 > 0 )
98 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
117#ifdef __GXX_EXPERIMENTAL_CXX0X__
122 spmatrix( std::initializer_list<std::initializer_list<double> > initializer_list ){
123 size_t const n1 = initializer_list.size();
124 size_t const n2 = initializer_list.begin()->size();
125 for(
auto l : initializer_list ){
126 if( l.size() != n2 ){
127 gsl::exception e(
"matrix rows have unequal sizes", __FILE__, __LINE__,
134 try {
count =
new size_t; }
catch( std::bad_alloc& e ){
143 for(
auto row : initializer_list ){
145 for(
auto x : row ){
set( r, c, x ); ++c; }
186 gsl_spmatrix_memcpy( copy.
get(),
get() );
229#ifdef __GXX_EXPERIMENTAL_CXX0X__
235 std::swap(
count, v.count );
236 v.ccgsl_pointer =
nullptr;
244 spmatrix( std::move( v ) ).swap( *
this );
275 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector", __FILE__, __LINE__, GSL_EFAULT );
282 if(
ccgsl_pointer == 0 ) gsl_error(
"null vector", __FILE__, __LINE__, GSL_EFAULT );
303 size_t nnz()
const {
return gsl_spmatrix_nnz(
get() ); }
308 char const*
type()
const {
return gsl_spmatrix_type(
get() ); }
326 gsl_spmatrix_csc( dest.get(),
get() );
336 gsl_spmatrix_csr( dest.get(),
get() );
380 int fprintf( FILE* stream,
char const* format )
const {
381 return gsl_spmatrix_fprintf( stream,
get(), format ); }
388 return gsl_spmatrix_fwrite( stream,
get() ); }
395 return gsl_spmatrix_fread( stream,
get() ); }
402 double get(
size_t const i,
size_t const j )
const {
403 return gsl_spmatrix_get(
get(), i, j ); }
411 int set(
size_t const i,
size_t const j,
double const x ){
412 return gsl_spmatrix_set(
get(), i, j, x ); }
419 double*
ptr(
size_t const i,
size_t const j )
const {
420 return gsl_spmatrix_ptr(
get(), i, j ); }
428 int minmax(
double& min_out,
double& max_out )
const {
429 return gsl_spmatrix_minmax(
get(), &min_out, &max_out ); }
436 int min_index(
size_t& imin_out,
size_t& jmin_out )
const {
437 return gsl_spmatrix_min_index(
get(), &imin_out, &jmin_out ); }
444 int scale(
double const x ){
return gsl_spmatrix_scale(
get(), x ); }
451 return gsl_spmatrix_scale_columns(
get(), x.
get() ); }
458 return gsl_spmatrix_scale_rows(
get(), x.
get() ); }
484 return gsl_spmatrix_realloc(
nzmax, spMatrix.
get() ); }
491 return gsl_spmatrix_nnz( spMatrix.
get() ); }
498 return gsl_spmatrix_type( spMatrix.
get() ); }
505 return gsl_spmatrix_set_zero( spMatrix.
get() ); }
512 return gsl_spmatrix_tree_rebuild( spMatrix.
get() ); }
521 gsl_spmatrix_csc( dest.get(), spMatrix.
get() );
531 gsl_spmatrix_csr( dest.get(), spMatrix.
get() );
548 spmatrix dest { gsl_spmatrix_compcol( spMatrix.
get() ) };
556 spmatrix dest { gsl_spmatrix_ccs( spMatrix.
get() ) };
564 spmatrix dest { gsl_spmatrix_crs( spMatrix.
get() ) };
573 return gsl_spmatrix_memcpy( dest.
get(), src.
get() ); }
582 return gsl_spmatrix_fprintf( stream, spMatrix.
get(), format ); }
589 return spmatrix { gsl_spmatrix_fscanf( stream ) }; }
597 return gsl_spmatrix_fwrite( stream, spMatrix.
get() ); }
605 return gsl_spmatrix_fread( stream, spMatrix.
get() ); }
614 return gsl_spmatrix_add( c.
get(),
a.get(),
b.get() ); }
623 gsl_spmatrix_add( c.get(),
a.get(),
b.get() );
626#ifndef GSL_DISABLE_DEPRECATED
634 return gsl_spmatrix_add_to_dense(
a.get(),
b.get() ); }
643 return gsl_spmatrix_dense_add(
a.get(),
b.get() ); }
651 return gsl_spmatrix_dense_sub(
a.get(),
b.get() ); }
658 return gsl_spmatrix_norm1(
a.get() ); }
666 return gsl_spmatrix_d2sp( S.
get(), A.
get() ); }
674 return gsl_spmatrix_sp2d( A.
get(), S.
get() ); }
682 return gsl_spmatrix_equal(
a.get(),
b.get() ); }
702 return gsl_spmatrix_transpose_memcpy( dest.
get(), src.
get() ); }
740#ifdef __GXX_EXPERIMENTAL_CXX0X__
This class is used to handle gsl exceptions so that gsl can use these rather than the GSL error handl...
@ GSL_EBADLEN
matrix, vector lengths are not conformant
This class handles matrix objects as shared handles.
gsl_matrix * get()
Get the gsl_matrix.
This class handles sparse matrix objects as shared handles.
spmatrix ccs() const
C++ version of gsl_spmatrix_ccs().
spmatrix compcol() const
C++ version of gsl_spmatrix_compcol().
static double norm1(gsl::spmatrix const &a)
C++ version of gsl_spmatrix_norm1().
double const * data() const
Give access to the data block.
int memcpy(spmatrix &dest) const
C++ version of gsl_spmatrix_memcpy().
char const * type() const
C++ version of gsl_spmatrix_type().
spmatrix(size_t const n1, size_t const n2, size_t nzmax, size_t sptype)
This constructor creates a new matrix with n1 rows and n2 columns.
static int sp2d(gsl::matrix &A, spmatrix const &S)
C++ version of gsl_spmatrix_sp2d().
int scale_rows(gsl::vector const &x)
C++ version of gsl_spmatrix_scale_rows().
static spmatrix fscanf(FILE *stream)
C++ version of gsl_spmatrix_fscanf().
int scale(double const x)
C++ version of gsl_spmatrix_scale().
int scale_columns(gsl::vector const &x)
C++ version of gsl_spmatrix_scale_columns().
int sptype() const
The type of the spmatrix.
static int tree_rebuild(spmatrix &spMatrix)
C++ version of gsl_spmatrix_tree_rebuild().
static int realloc(size_t const nzmax, gsl::spmatrix &spMatrix)
C++ version of gsl_spmatrix_realloc(): matches a function in gsl that is intended for internal use.
static int fread(FILE *stream, spmatrix &spMatrix)
C++ version of gsl_spmatrix_fread().
int realloc(size_t const nzmax)
C++ version of gsl_spmatrix_realloc().
gsl_spmatrix const * get() const
Get the gsl_spmatrix.
static int transpose_memcpy(spmatrix &dest, spmatrix const &src)
C++ version of gsl_spmatrix_transpose_memcpy().
static spmatrix crs(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_crs().
double * ptr(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_ptr().
static spmatrix compcol(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_compcol().
size_t nzmax() const
The maximum number of nonzero elements.
int tree_rebuild()
C++ version of gsl_spmatrix_tree_rebuild().
int set_zero()
C++ version of gsl_spmatrix_set_zero().
gsl_spmatrix * ccgsl_pointer
The shared pointer.
spmatrix(size_t const n1, size_t const n2)
This constructor creates a new matrix with n1 rows and n2 columns.
double * data()
Give access to the data block.
int transpose2()
C++ version of gsl_spmatrix_transpose2().
static int dense_sub(gsl::matrix &a, spmatrix const &b)
C++ version of gsl_spmatrix_dense_sub().
size_t size2() const
The number of columns of the matrix.
spmatrix(gsl_spmatrix *v)
Could construct from a gsl_spmatrix.
int set(size_t const i, size_t const j, double const x)
C++ version of gsl_spmatrix_set().
static int memcpy(spmatrix &dest, spmatrix const &src)
C++ version of gsl_spmatrix_memcpy().
static size_t nnz(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_nnz().
gsl_spmatrix * get()
Get the gsl_spmatrix.
int minmax(double &min_out, double &max_out) const
C++ version of gsl_spmatrix_minmax().
spmatrix & operator=(spmatrix &&v)
Move operator.
~spmatrix()
The destructor only deletes the pointers if count reaches zero.
int fprintf(FILE *stream, char const *format) const
C++ version of gsl_spmatrix_fprintf().
static int transpose2(spmatrix &a)
C++ version of gsl_spmatrix_transpose2().
void wrap_gsl_spmatrix_without_ownership(gsl_spmatrix *v)
This function is intended mainly for internal use.
spmatrix(spmatrix const &v)
The copy constructor.
size_t use_count() const
Find how many spmatrix objects share this pointer.
spmatrix csc() const
C++ version of gsl_spmatrix_csc().
spmatrix(std::initializer_list< std::initializer_list< double > > initializer_list)
Could construct from a std::initializer_list in C++11 and later.
spmatrix compress(int const sptype) const
C++ version of gsl_spmatrix_compress().
static spmatrix compress(spmatrix const &spMatrix, int const sptype)
C++ version of gsl_spmatrix_compress().
size_t size1() const
The number of rows of the matrix.
static spmatrix csc(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_csc().
int fread(FILE *stream)
C++ version of gsl_spmatrix_fread().
static int equal(spmatrix const &a, spmatrix const &b)
C++ version of gsl_spmatrix_equal().
spmatrix crs() const
C++ version of gsl_spmatrix_crs().
spmatrix & operator=(spmatrix const &v)
The assignment operator.
static int d2sp(gsl::spmatrix &S, gsl::matrix const &A)
C++ version of gsl_spmatrix_d2sp().
double get(size_t const i, size_t const j) const
C++ version of gsl_spmatrix_get().
static spmatrix add(spmatrix const &a, spmatrix const &b)
C++ version of gsl_spmatrix_add().
int fwrite(FILE *stream) const
C++ version of gsl_spmatrix_fwrite().
static int fwrite(FILE *stream, spmatrix &spMatrix)
C++ version of gsl_spmatrix_fwrite().
int equal(spmatrix const &b) const
C++ version of gsl_spmatrix_equal().
spmatrix clone() const
The clone function.
bool unique() const
Find if this is the only object sharing the gsl_spmatrix.
static int set_zero(spmatrix &spMatrix)
C++ version of gsl_spmatrix_set_zero().
spmatrix()
The default constructor is only really useful for assigning to.
spmatrix csr() const
C++ version of gsl_spmatrix_csr().
static int transpose(spmatrix &a)
C++ version of gsl_spmatrix_transpose().
spmatrix(spmatrix &&v)
Move constructor.
static char const * type(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_type().
int min_index(size_t &imin_out, size_t &jmin_out) const
C++ version of gsl_spmatrix_min_index().
static spmatrix csr(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_csr().
static int dense_add(gsl::matrix &a, spmatrix const &b)
C++ version of gsl_spmatrix_dense_add().
static int fprintf(FILE *stream, spmatrix const &spMatrix, char const *format)
C++ version of gsl_spmatrix_fprintf().
static int add_to_dense(gsl::matrix &a, spmatrix const &b)
C++ version of gsl_spmatrix_add_to_dense().
size_t nnz() const
C++ version of gsl_spmatrix_nnz().
int transpose()
C++ version of gsl_spmatrix_transpose().
static int add(spmatrix &c, spmatrix const &a, spmatrix const &b)
C++ version of gsl_spmatrix_add().
void swap(spmatrix &m)
Swap two spmatrix objects.
void reset()
Stop sharing ownership of the shared pointer.
@ TRIPLET
GSL_SPMATRIX_TRIPLET.
static spmatrix ccs(spmatrix const &spMatrix)
C++ version of gsl_spmatrix_ccs().
size_t * count
The shared reference count.
This class handles vector objects as shared handles.
gsl_vector * get()
Get the gsl_vector.
double b(int order, double qq)
C++ version of gsl_sf_mathieu_b().
double a(int order, double qq)
C++ version of gsl_sf_mathieu_a().
The gsl package creates an interface to the GNU Scientific Library for C++.